Repository navigation
Fix reflected operator priority when the right operand is a subclass - #11662
Nithin (nithin42) wants to merge 5 commits into
Conversation
|
🔒 Automated review in progress — Heejae Chang (@heejaechang) is auto-reviewing this PR. |
🔴 Pyright CLI QA —
|
Python calls the reflected form of a binary operator first when the right operand's type is a proper subclass of the left operand's type and overrides the reflected magic method. Pyright always tried the left operand's method first, so `int() & Flags.A` for an IntFlag subclass evaluated to int instead of Flags.
c0913e2 to
ee02130
Compare
Restore inherited member contracts and bound-method handling. Preserve function alias identity, handle prioritized NotImplemented fallbacks, and bound ancestry checks with the existing MRO. Add regression coverage for dispatch, aliases, and inherited attributes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
I tightened the reflected-method check to distinguish actual overrides from aliases of the same implementation, while keeping the original The regression cases and both affected evaluator suites pass (344 tests), along with the TypeScript build, changed-file lint/format checks, and CPython checks. Targeted timing comparisons no longer show the identified scaling regression. I haven't run the full repository suite, and the pre-existing metaclass and inherited comparison-priority gaps are still outside this change. |
|
Thanks for tightening this up, Rich Chiodo (@rchiodo)! Distinguishing real overrides from aliased base methods, falling back cleanly on |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Classify these regressions as Pyright inference limitations (B). Restore validated alias parameter and generic types while resolving callable identity only for operator dispatch. Require genuine subclass evidence before prioritizing reflected methods on synthesized intersections, and handle class operands through their effective metaclasses. Add exact signature, consumer, alias-chain, intersection, and metaclass regressions without weakening existing type expectations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Class B / Pyright limitation: ordinary arithmetic could leak the Any-derived NotImplementedType sentinel and disable downstream assignment and return checking. Preserve subclass dispatch priority while combining successful results and following valid fallback paths, including same-runtime-class restrictions. Add precise regression coverage for chained arithmetic, partial decline, Never, None, direct calls, and metaclasses. No typeshed changes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Classify the xarray false positives as a Pyright inference limitation (B), not a typeshed change. Reuse bounded call-site inference for inherited unannotated methods inferred as NotImplemented, supplying the actual bound receiver and synthetic argument types. Retain explicit return contracts and reject fully Unknown refinements. Cover normal, reflected, and metaclass calls, py.typed libraries, and unsafe Self or decorated-overload shortcuts without weakening existing type expectations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
- .../projects/sympy/sympy/algebras/quaternion.py:726:16 - error: Type "Expr" is not assignable to return type "Quaternion"
- "Expr" is not assignable to "Quaternion" (reportReturnType)
- .../projects/sympy/sympy/algebras/quaternion.py:1700:16 - error: Type "Expr" is not assignable to return type "Quaternion"
- "Expr" is not assignable to "Quaternion" (reportReturnType)
+ .../projects/sympy/sympy/assumptions/refine.py:199:31 - error: Argument of type "One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Float | Expr | Infinity | NegativeInfinity | Unknown" cannot be assigned to parameter "element" of type "Rational" in function "add"
+ Type "One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Float | Expr | Infinity | NegativeInfinity | Unknown" is not assignable to type "Rational"
+ "Expr" is not assignable to "Rational" (reportArgumentType)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "NaN"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "ComplexInfinity"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "Rational"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "Zero"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "Infinity"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "NegativeInfinity"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "Float"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "One"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "NegativeOne"
+ Attribute "as_two_terms" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/assumptions/refine.py:208:31 - error: Cannot access attribute "as_two_terms" for class "Integer"
- .../projects/sympy/sympy/combinatorics/character_table.py:504:30 - error: Argument of type "Expr | Unknown | One | Poly | Any" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+ .../projects/sympy/sympy/combinatorics/character_table.py:504:30 - error: Argument of type "Expr | Unknown | One | Poly" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Expr | Unknown | One | Poly | Any" is not assignable to type "ConvertibleToInt"
+ Type "Expr | Unknown | One | Poly" is not assignable to type "ConvertibleToInt"
- .../projects/sympy/sympy/combinatorics/character_table.py:504:30 - error: Argument of type "Expr | Unknown | One | Poly | Any" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
+ .../projects/sympy/sympy/combinatorics/character_table.py:504:30 - error: Argument of type "Expr | Unknown | One | Poly" cannot be assigned to parameter "x" of type "ConvertibleToInt" in function "__new__"
- Type "Expr | Unknown | One | Poly | Any" is not assignable to type "ConvertibleToInt"
+ Type "Expr | Unknown | One | Poly" is not assignable to type "ConvertibleToInt"
+ .../projects/sympy/sympy/concrete/tests/test_products.py:101:12 - error: No overloads for "simplify" match the provided arguments (reportCallIssue)
- Operator "*" not supported for types "tuple[Unknown, ...]" and "tuple[Unknown, ...]" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "tuple[Unknown, ...]" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "Basic*" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "Basic*" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "Product" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "Product" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "Basic" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "Basic" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "Expr" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "Expr" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "Equality" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "Equality" when expected type is "Basic"
- Operator "*" not supported for types "tuple[Unknown, ...]" and "NaN" when expected type is "Expr"
+ Operator "*" not supported for types "tuple[Unknown, ...]" and "NaN" when expected type is "Basic"
- Operator "*" not supported for types "Basic*" and "tuple[Unknown, ...]" when expected type is "Expr"
+ Operator "*" not supported for types "Basic*" and "tuple[Unknown, ...]" when expected type is "Basic"
+ .../projects/sympy/sympy/concrete/tests/test_products.py:101:21 - error: Argument of type "Unknown | tuple[Unknown, ...] | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Expr" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+ Type "Unknown | tuple[Unknown, ...] | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Expr" is not assignable to type "Basic"
+ "tuple[Unknown, ...]" is not assignable to "Basic" (reportArgumentType)
- .../projects/sympy/sympy/concrete/tests/test_products.py:158:25 - error: Operator "/" not supported for types "tuple[Unknown, ...] | Unknown | Self@Basic | Product | Basic | Expr | One | BooleanFalse | BooleanTrue | Equality | NaN" and "Unknown | tuple[Unknown, ...] | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Expr | Infinity | NegativeInfinity | Float | NotImplementedType"
+ .../projects/sympy/sympy/concrete/tests/test_products.py:158:25 - error: Operator "/" not supported for types "tuple[Unknown, ...] | Unknown | Self@Basic | Product | Basic | Expr | One | BooleanFalse | BooleanTrue | Equality | NaN" and "Unknown | tuple[Unknown, ...] | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Expr"
+ .../projects/sympy/sympy/core/add.py:333:17 - error: Argument of type "Number | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Expr" cannot be assigned to parameter "value" of type "Number" in function "__setitem__"
+ Type "Number | One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Expr" is not assignable to type "Number"
+ "Expr" is not assignable to "Number" (reportArgumentType)
- .../projects/sympy/sympy/core/add.py:1084:46 - error: Operator "+" not supported for types "One | Zero | Unknown | None" and "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | NotImplementedType | Expr | Unknown"
+ .../projects/sympy/sympy/core/add.py:1084:46 - error: Operator "+" not supported for types "One | Zero | Unknown | None" and "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Expr | Unknown"
+ .../projects/sympy/sympy/core/add.py:1183:9 - error: Method "as_content_primitive" overrides class "Expr" in an incompatible manner
+ Return type mismatch: base method returns type "tuple[One, Expr]", override returns type "tuple[One | NegativeOne | Zero | Integer | Expr | ComplexInfinity | NaN | Rational | Infinity | NegativeInfinity | Float | Unknown, Expr | Unknown | Add]"
+ "tuple[One | NegativeOne | Zero | Integer | Expr | ComplexInfinity | NaN | Rational | Infinity | NegativeInfinity | Float | Unknown, Expr | Unknown | Add]" is not assignable to "tuple[One, Expr]"
+ Tuple entry 1 is incorrect type
+ Type "One | NegativeOne | Zero | Integer | Expr | ComplexInfinity | NaN | Rational | Infinity | NegativeInfinity | Float | Unknown" is not assignable to type "One"
+ "Expr" is not assignable to "One" (reportIncompatibleMethodOverride)
+ .../projects/sympy/sympy/core/add.py:1183:9 - error: Method "as_content_primitive" overrides class "Basic" in an incompatible manner
+ Return type mismatch: base method returns type "tuple[One, Self@Basic]", override returns type "tuple[One | NegativeOne | Zero | Integer | Expr | ComplexInfinity | NaN | Rational | Infinity | NegativeInfinity | Float | Unknown, Expr | Unknown | Add]"
+ "tuple[One | NegativeOne | Zero | Integer | Expr | ComplexInfinity | NaN | Rational | Infinity | NegativeInfinity | Float | Unknown, Expr | Unknown | Add]" is not assignable to "tuple[One, Self@Basic]"
+ Tuple entry 1 is incorrect type
... (truncated 933 lines) ...
core (https://github.com/home-assistant/core)
- .../projects/core/homeassistant/components/aprilaire/climate.py:115:16 - error: Type "int" is not assignable to return type "ClimateEntityFeature"
- "int" is not assignable to "ClimateEntityFeature" (reportReturnType)
- .../projects/core/homeassistant/components/zwave_js/cover.py:98:41 - error: Cannot assign to attribute "_attr_supported_features" for class "CoverPositionMixin*"
- Type "CoverEntityFeature | int" is not assignable to type "CoverEntityFeature | None"
- Type "int" is not assignable to type "CoverEntityFeature | None"
- "int" is not assignable to "CoverEntityFeature"
- "int" is not assignable to "None" (reportAttributeAccessIssue)
- .../projects/core/homeassistant/components/zwave_js/cover.py:111:13 - error: Operator "|=" not supported for types "CoverEntityFeature | None" and "Literal[CoverEntityFeature.STOP]"
- Operator "|" not supported for types "None" and "Literal[CoverEntityFeature.STOP]" (reportOperatorIssue)
- .../projects/core/homeassistant/components/zwave_js/cover.py:266:41 - error: Cannot assign to attribute "_attr_supported_features" for class "CoverTiltMixin*"
- Type "CoverEntityFeature | int" is not assignable to type "CoverEntityFeature | None"
- Type "int" is not assignable to type "CoverEntityFeature | None"
- "int" is not assignable to "CoverEntityFeature"
- "int" is not assignable to "None" (reportAttributeAccessIssue)
- .../projects/core/homeassistant/components/zwave_js/cover.py:279:13 - error: Operator "|=" not supported for types "CoverEntityFeature | None" and "Literal[CoverEntityFeature.STOP_TILT]"
- Operator "|" not supported for types "None" and "Literal[CoverEntityFeature.STOP_TILT]" (reportOperatorIssue)
- 43394 errors, 79 warnings, 0 informations
+ 43389 errors, 79 warnings, 0 informations
xarray (https://github.com/pydata/xarray)
+ .../projects/xarray/xarray/coding/cftime_offsets.py:164:16 - error: Operator "+" not supported for types "BaseCFTimeOffset*" and "Unknown | BaseCFTimeOffset*"
+ Operator "+" not supported for types "BaseCFTimeOffset*" and "BaseCFTimeOffset*" (reportOperatorIssue)
- 2618 errors, 219 warnings, 0 informations
+ 2619 errors, 219 warnings, 0 informations
pytensor (https://github.com/pymc-devs/pytensor)
- Parameter 4 name mismatch: base parameter is named "cotangents", override parameter is named "gout" (reportIncompatibleMethodOverride)
+ Parameter 4 name mismatch: base parameter is named "cotangents", override parameter is named "gout"
+ Return type mismatch: base method returns type "list[Variable[Unknown, Unknown]]", override returns type "list[Unknown] | list[Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | None]"
+ Type "list[Unknown] | list[Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | None]" is not assignable to type "list[Variable[Unknown, Unknown]]"
+ "list[Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | None]" is not assignable to "list[Variable[Unknown, Unknown]]"
+ Type parameter "_T@list" is invariant, but "Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | None" is not the same as "Variable[Unknown, Unknown]"
+ Consider switching from "list" to "Sequence" which is covariant (reportIncompatibleMethodOverride)
- .../projects/pytensor/pytensor/tensor/linalg/solvers/linear_control.py:440:53 - error: Operator "*" not supported for types "float" and "TensorVariable[Unknown, Unknown] | Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Any | NotImplementedType | None"
+ .../projects/pytensor/pytensor/tensor/linalg/solvers/linear_control.py:440:53 - error: Operator "*" not supported for types "float" and "TensorVariable[Unknown, Unknown] | Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Any | None"
- .../projects/pytensor/pytensor/tensor/linalg/solvers/linear_control.py:443:9 - error: Operator ">" not supported for types "TensorVariable[Unknown, Unknown] | Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Any | NotImplementedType | None" and "None"
+ .../projects/pytensor/pytensor/tensor/linalg/solvers/linear_control.py:443:9 - error: Operator ">" not supported for types "TensorVariable[Unknown, Unknown] | Unknown | Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Any | None" and "None"
- .../projects/pytensor/pytensor/tensor/math.py:2788:21 - error: Operator "*" not supported for types "int | Unknown | NotImplementedType" and "Unbound | TensorConstant[Unknown] | Unknown | None"
+ .../projects/pytensor/pytensor/tensor/math.py:2788:21 - error: Operator "*" not supported for types "int | Unknown" and "Unbound | TensorConstant[Unknown] | Unknown | None"
- .../projects/pytensor/pytensor/tensor/rewriting/math.py:1879:23 - error: Operator "*" not supported for types "Unknown | NotImplementedType | TensorConstant[Unknown] | None" and "Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Unknown"
+ .../projects/pytensor/pytensor/tensor/rewriting/math.py:1879:23 - error: Operator "*" not supported for types "Unknown | TensorConstant[Unknown] | None" and "Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Unknown"
- .../projects/pytensor/pytensor/tensor/rewriting/math.py:1881:23 - error: Operator "/" not supported for types "Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Unknown" and "Unknown | NotImplementedType | TensorConstant[Unknown] | None"
+ .../projects/pytensor/pytensor/tensor/rewriting/math.py:1881:23 - error: Operator "/" not supported for types "Variable[Unknown, Unknown] | list[Variable[Unknown, Unknown]] | Unknown" and "Unknown | TensorConstant[Unknown] | None"
+ Type "int" is not assignable to type "slice[Any, Any, Any] | TensorVariable[Unknown, Unknown]"
+ "int" is not assignable to "slice[Any, Any, Any]"
+ "int" is not assignable to "TensorVariable[Unknown, Unknown]" (reportReturnType)
+ .../projects/pytensor/pytensor/tensor/subtensor.py:445:24 - error: Type "tuple[int | Incomplete | Unknown, Literal[1]]" is not assignable to return type "tuple[slice[Any, Any, Any] | TensorVariable[Unknown, Unknown], int | TensorVariable[Unknown, Unknown]]"
+ Type "int | Incomplete | Unknown" is not assignable to type "slice[Any, Any, Any] | TensorVariable[Unknown, Unknown]"
- 5515 errors, 68 warnings, 0 informations
+ 5516 errors, 68 warnings, 0 informations
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ .../projects/pandas-stubs/tests/scalars/test_scalars.py:581:54 - error: Unnecessary "# pyright: ignore" rule: "reportAssertTypeFailure" (reportUnnecessaryTypeIgnoreComment)
+ .../projects/pandas-stubs/tests/scalars/test_scalars.py:622:54 - error: Unnecessary "# pyright: ignore" rule: "reportAssertTypeFailure" (reportUnnecessaryTypeIgnoreComment)
- 208 errors, 3 warnings, 0 informations
+ 210 errors, 3 warnings, 0 informations
jax (https://github.com/google/jax)
+ .../projects/jax/jax/_src/pallas/mosaic_gpu/lowering.py:4426:13 - error: Argument of type "FragmentedArray" cannot be assigned to parameter "start" of type "int | Array" in function "__init__"
+ Type "FragmentedArray" is not assignable to type "int | Array"
+ "FragmentedArray" is not assignable to "int"
+ "FragmentedArray" is not assignable to "Array" (reportArgumentType)
+ .../projects/jax/jax/_src/pallas/mosaic_gpu/lowering.py:4431:9 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+ .../projects/jax/jax/_src/pallas/mosaic_gpu/lowering.py:4431:9 - error: Argument of type "FragmentedArray" cannot be assigned to parameter "value" of type "Slice" in function "__setitem__"
+ "FragmentedArray" is not assignable to "Slice" (reportArgumentType)
- 3706 errors, 72 warnings, 0 informations
+ 3709 errors, 72 warnings, 0 informations
|
mypy_primer analysisAdvisory AI analysis of primer run 40600722580, attempt 1 Regression review required. Potential regressions or recorded warning signals are listed first; causation must be established separately. Potential regressionssympy: Receiver-bound operator reinference removes NotImplemented/Any alternatives but produces broad new errors across SymPy; precision improves, yet polymorphic operator bodies may now be over-specialized.Regression warning signals require review, regardless of the AI assessment:
AI assessment: Possible regression (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: The recorded baseline often retained NotImplementedType or Any in operator-result unions. At assumptions/refine.py:199/208 there were no diagnostics for the Rational.add argument or as_two_terms access; quaternion.py:726 and :1700 instead reported Expr returned where Quaternion was required. The manifest's gradual signal is chiefly Any/NotImplemented disappearing, not an observed container becoming Any. After / PR evidence: The PR run reports a concrete union of SymPy numeric/Expr subclasses plus Unknown at refine.py:199 and flags as_two_terms on many union members at :208. Many operator diagnostics are same-location rewrites with NotImplementedType removed, but new call, override, attribute, and iteration diagnostics also appear; the two Quaternion return errors disappear. Why this matters: Users gain checking that Any/NotImplemented previously diluted, but can no longer rely on inherited unannotated operators remaining declined/gradual. If the bound receiver does not determine every dynamic helper path, valid symbolic code can acquire attribute, overload, and override errors. Conversely, the removed Quaternion errors may be useful corrected inference rather than suppression. Causal analysis: At the exact head, getNotImplementedInferenceReceiver selects an inherited unannotated method only when its inferred return is types.NotImplementedType and the bound receiver differs from the declaring class. _getInferredReturnTypeResult then invokes call-site inference with that receiver, and inferReturnTypeForCallSite supplies the concrete receiver and argument types. SymPy's heavily inherited arithmetic therefore loses NotImplemented branches and often Any, exposing concrete Expr subclasses to normal argument/member checks. That causal path explains both the widespread NotImplemented-only message rewrites and newly reachable diagnostics. It does not by itself prove the new unions are sound: helper overrides and reflected-operator priority are highly polymorphic, while the raw diff contains mixed additions and removals. The gradual-detail signal is counterevidence to type erasure because precision generally increases, but Unknown remains and several old checks vanish, so this should not be blanket-classified as improvement. Uncertainty / next check: The exact synthetic merge SHA and ecosystem checkout were not visible in the retrieved logs. Minimize one affected hierarchy: inherited __add__ delegates to an overridable helper; use a positive subclass whose helper returns a concrete symbolic type and a negative subclass that conditionally returns NotImplemented. Compare direct, reflected, and base-typed calls plus the refine.py:208 member access.
xarray: A new error appears inside BaseCFTimeOffset.__rsub__ for -self + other; the PR preserves Unknown for a polymorphic base path, so valid subclass dispatch may now be rejected.AI assessment: Possible regression (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: The recorded baseline emitted no diagnostic at cftime_offsets.py:164. This is not evidence of an observed reveal type, only that the method body was accepted under the baseline operator inference. After / PR evidence: The PR run reports that BaseCFTimeOffset + (Unknown | BaseCFTimeOffset) is unsupported at cftime_offsets.py:164, with a detail specifically rejecting BaseCFTimeOffset + BaseCFTimeOffset. The PR's own analogous polymorphic-offset test expects an intermediate result to remain Unknown and marks the surrounding operator path as an error. Why this matters: Authors of extensible offset bases can no longer rely on an inherited operator body that delegates to subclass behavior type-checking cleanly. A runtime-valid concrete subclass may be rejected while the body is checked against the base receiver, forcing an annotation, cast, or ignore and reducing usefulness of subclass-specific operator inference. Causal analysis: The new gate refines only when the bound receiver differs from the method's declaring class. Concrete subclass calls can therefore be re-analyzed with the subclass receiver, but analysis of the polymorphic BaseCFTimeOffset method body still sees the base contract. The exact-head operator18 control deliberately keeps a similar '-self + other' result Unknown and expects an error for the base/helper contract. That decision plausibly causes the new line-164 diagnostic. Counterevidence is that a bare BaseCFTimeOffset may genuinely decline addition at runtime, so rejecting Base + Base could be correct. The concern is whether the implementation body is intended only as a template for concrete offsets; the raw diff alone cannot establish that intent. Uncertainty / next check: Resolve the exact xarray revision and inspect BaseCFTimeOffset.apply plus concrete overrides. Positive control: a concrete final offset whose helper accepts/returns itself should type as that offset. Negative control: a base instance or subclass that retains NotImplemented should still report unsupported +. Also test __rsub__ through a base-typed parameter.
pytensor: Most changes are precision rewrites removing NotImplementedType, but a newly exposed invariant-list override mismatch and subtensor return error need call-path validation.Regression warning signals require review, regardless of the AI assessment:
AI assessment: Needs human review (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: Several existing operator errors included NotImplementedType in unions at linear_control.py:440/:443, tensor/math.py:2788, and rewriting/math.py:1879/:1881. The override diagnostic reported only a parameter-name mismatch. No return error was reported at subtensor.py:445. After / PR evidence: The same operator locations remain errors but lose NotImplementedType, so those are message/detail rewrites rather than new checks. The override now additionally reports list[Unknown | Variable | list[Variable] | None] incompatible with list[Variable]. A new subtensor.py:445 return error says the first tuple element may be int | Incomplete | Unknown rather than slice | TensorVariable. Why this matters: Removing a decline-only branch gives more useful operator types. However, downstream implementers can no longer rely on the override passing apart from its parameter name, and a subtensor helper can no longer return its inferred tuple without a cast/annotation. These may expose real annotation gaps or may be false positives from receiver-specific reinference. Causal analysis: At the exact head, inherited unannotated methods cached as NotImplemented are re-analyzed with the bound receiver and actual arguments. This directly explains NotImplementedType disappearing at unchanged operator locations and can make formerly gradual return paths concrete enough for invariant list and declared-return checks. The manifest's gradual signal therefore reflects increased precision, not type erasure. The new override details and subtensor return diagnostic are potentially useful restored checking, but the raw concise diff omits the override header/location and cannot safely associate its detail lines with a specific declaration. Nor was the complete operator/helper chain for subtensor available at the recorded ecosystem revision. That missing context prevents deciding whether the declarations are wrong or the checker over-specialized a dynamic path. Uncertainty / next check: Locate the override header in full baseline/new output and inspect its base/derived return declarations. For subtensor.py:445, reveal each tuple element before return under a concrete TensorVariable receiver and under a base/unknown receiver; verify the int branch is truly impossible before calling this an exposed typing issue.
jax: Receiver-bound operator inference now feeds FragmentedArray into index/slice APIs, adding argument and overload errors; this may preserve the wrong retained candidate for JAX's DSL.AI assessment: Possible regression (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: The recorded baseline emitted no errors at mosaic_gpu/lowering.py:4426 or :4431. The raw diff does not expose the baseline expression type, so it is unknown whether these calls previously relied on NotImplemented fallback, Any, or a different overload result. After / PR evidence: At :4426 a FragmentedArray is rejected as slice.__init__ start (expected int | Array). At :4431 __setitem__ has no matching overload and rejects FragmentedArray where Slice is expected. The outer FragmentedArray API is retained rather than erased to Any/Unknown, but it no longer satisfies the downstream indexing contracts. Why this matters: JAX lowering code that uses overloaded FragmentedArray arithmetic to construct DSL indices can no longer type-check. Users lose reliance on those expressions being accepted by slice/index overloads; if FragmentedArray is intentionally converted or supported by the DSL, these are false positives rather than useful errors. Causal analysis: The exact-head PR re-analyzes inherited, unannotated operators cached as NotImplemented with the concrete receiver and actual operand types. It also guards against accepting a wholly Unknown refinement. That can replace a declined/gradual operator result with FragmentedArray, after which normal argument checking reaches slice and __setitem__ and reports the observed incompatibilities. This is causally consistent and not type erasure. However, the available evidence does not show the operator declaration or whether JAX's indexing abstraction intentionally accepts this value through conversion. The added diagnostics could expose a missing annotation/overload, but blaming JAX would require inspecting that full overload set at the exact recorded revision, so a checker regression remains credible. Uncertainty / next check: Inspect FragmentedArray's relevant normal/reflected operator and the target __setitem__/Slice overloads at the exact checkout. Positive control: the operator result should satisfy the intended DSL index protocol and preserve FragmentedArray members. Negative control: passing a raw unrelated FragmentedArray to built-in slice must still fail.
Other project assessmentscore: Inherited IntFlag-style operators now preserve Home Assistant feature-enum results, removing spurious int assignments and optional bitwise errors rather than erasing checking.AI assessment: Expected improvement (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: The baseline treated feature expressions as int in aprilaire/climate.py:115 and as CoverEntityFeature | int in zwave_js/cover.py:98 and :266. It consequently rejected enum-typed returns/attributes and then also rejected |= at :111/:279 because the destination could be None. After / PR evidence: Those diagnostics disappear. There is no evidence that the values became Any or Unknown; the removed details specifically identify the incompatible alternative as int, consistent with receiver-bound operator inference retaining the feature enum type. Why this matters: Downstream entity code can combine feature flags and return them under ClimateEntityFeature/CoverEntityFeature annotations without casts or ignores. It still relies on the enum operator implementation being modeled as returning the concrete enum rather than bare int. Causal analysis: The exact-head change re-analyzes an inherited unannotated operator when its cached result is only NotImplemented, supplying the concrete subclass receiver and call argument types. That allows a feature enum/IntFlag subclass path to infer its concrete result instead of falling back to an int-containing result. The observed removals line up: int is the only problematic branch in the return and attribute diagnostics, and eliminating it also prevents the cascading optional |= complaints. No removed-check or type-erasure signal is recorded for this project. The conclusion is about static inference, not runtime behavior. Confidence is limited because the workflow's exact synthetic merge SHA and exact Home Assistant checkout were not recovered; the pinned source is a nearby revision. Uncertainty / next check: Confirm on the recorded checkout that the expressions at all five locations dispatch through the inherited unannotated operator selected by the new gate. A negative control should use an explicitly annotated operator returning int; its assignment to the feature enum must still fail.
pandas-stubs: Two assert_type suppressions become unnecessary, indicating inherited scalar arithmetic now reaches the expected concrete result rather than failing the assertion.AI assessment: Expected improvement (medium confidence). PR attribution: Likely caused by the PR. Before / baseline evidence: At test_scalars.py:581 and :622 the baseline needed pyright ignores specifically for reportAssertTypeFailure. An assertion's target type is an expectation, not an observed baseline reveal; the evidence establishes only that baseline Pyright disagreed with those expected scalar-operation types. After / PR evidence: The PR run reports both ignores as unnecessary. Thus the same assert_type checks no longer emit reportAssertTypeFailure, consistent with receiver-bound reinference selecting the concrete pandas scalar result. No new Any/Unknown or erased outer API is reported. Why this matters: Stub consumers can rely on these scalar arithmetic expressions retaining the asserted pandas/stdlib scalar API without suppressing Pyright. Member access and subsequent operator checks on the concrete result remain available rather than being weakened to a gradual type. Causal analysis: The exact-head change detects inherited unannotated operators whose cached return is only NotImplementedType, then analyzes their body using the concrete bound receiver and call arguments. Pandas scalar/reflected arithmetic frequently depends on subclass dispatch and operator priority, so this can change the selected inferred result to the concrete type expected by assert_type. The only recorded diagnostics are unnecessary-ignore reports, which is positive evidence that checking became more precise rather than disappearing. Still, the concise diff does not print the assertion expressions or expected types, and the exact ecosystem checkout was not recovered; therefore the conclusion is medium-confidence and does not claim a runtime fix. Uncertainty / next check: Inspect the exact recorded lines to name both expected result types. Positive controls should access a member unique to each asserted result; a negative control should pass an unsupported operand and still produce an operator error rather than Any/Unknown.
Full evidence and limitations: download |
|
Compared candidate View the full release history charts with the base and PR results. Execution time historyPeak memory historyType checker benchmark🟢 No performance regressions detected. Regression threshold:
Pyright stats
|
|
Hmm, having a hard time getting the primer to pass. Going to try something different. |
|
Rich Chiodo (@rchiodo) a question about review order, not this PR: since late September, outside PRs have merged in PR-number order, and nothing behind #11662 has merged while it's been in progress. That includes #11666 and #11691, which have been approved and mergeable for a while. Is the queue meant to wait on the PR at its head while that PR needs changes, or should approved PRs behind it be able to go in? |
I'm trying to do them in order, but some fixes seem more important than others (like the hang one you were working on). This one in particular is stuck on me trying to fix the loss of type information when returning 'self' typed parameters. So yes, I'm trying to do them from oldest to newest in case the older ones fix PRs that were added later. |
|
Sorry closing this in favor of #11977. I think that fix was simpler than this one. |
Fixes #11515
Root cause
There are two separate problems behind the reported symptom.
1. The reflected form of the operator is never given priority.
Python evaluates
x op yby callingtype(x).__op__first, except in one case: iftype(y)is a proper subclass oftype(x)and it overrides the reflected method__rop__, thentype(y).__rop__is called first.validateArithmeticOperationinoperations.tsalways tried the left operand's method first and only fell back to the reflected form if that failed. Sinceint.__and__accepts anyint, it always won, and the more precise result fromIntFlag.__rand__was never considered.2. An undeclared class member does not override a declared method in a base class.
getTypeOfClassMemberNamelooks for a member with a declared type first, walking the whole MRO before falling back to a lookup that also accepts inferred types. When a derived class defines a member through a plain assignment, that member has no declared type, so the lookup skipped it and returned a declared member from a base class instead.typeshed defines
IntFlag's reflected methods with the alias idiom:intalready declares__rand__, soFlags.A.__rand__resolved toint.__rand__((value: int, /) -> int) rather than the alias. Even with the operator ordering fixed, the reflected call would still have producedint.Fix
operations.tsnow checks, before calling the left operand's magic method, whether the right operand's type is a proper subclass of the left operand's type and overrides the reflected magic method. If so, the reflected method is tried first, with the existing evaluation order used as a fallback so nothing regresses when the reflected call doesn't apply.typeEvaluator.tsuses the existing but previously unusedskippedUndeclaredTypeflag onClassMember. When the declared-types-only lookup skipped an undeclared symbol in a class earlier in the MRO and the declared symbol it found is a method, the overriding symbol is used instead. This is deliberately limited to methods so thatreportIncompatibleVariableOverridebehavior for variable overrides is unchanged.Verification
New sample
operator13.pyregistered intypeEvaluator8.test.tscovers:int() & Flags.A,|and^now evaluate toFlagsint() & int()still evaluates toint__radd__takes priority over the base class__add____radd__keeps the normal evaluation orderReverting either source change makes the new test fail. With both applied, all 1285 tests across the
typeEvaluator*andcheckersuites pass with no regressions.