Skip to content

Fix type narrowing bug#11364

Open
gramster wants to merge 1 commit intomicrosoft:mainfrom
gramster:fix-pyright-type-narrowing-bug
Open

Fix type narrowing bug#11364
gramster wants to merge 1 commit intomicrosoft:mainfrom
gramster:fix-pyright-type-narrowing-bug

Conversation

@gramster
Copy link
Copy Markdown
Member

@gramster gramster commented Apr 7, 2026

Fix isMaybeDescriptorInstance to use MRO lookup for inherited descriptors

Updated isMaybeDescriptorInstance to use lookUpObjectMember for MRO-aware lookup of get and set methods, fixing all ~6 call sites that were broken for descriptor subclasses. Simplified typeGuards.ts to use the fixed utility function instead of custom MRO lookup logic.

Fixes #11039

…tors

Updated isMaybeDescriptorInstance to use lookUpObjectMember for MRO-aware
lookup of __get__ and __set__ methods, fixing all ~6 call sites that were
broken for descriptor subclasses. Simplified typeGuards.ts to use the fixed
utility function instead of custom MRO lookup logic.
@gramster gramster requested review from heejaechang and rchiodo April 7, 2026 01:00
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Diff from mypy_primer, showing the effect of this PR on open source code:

sympy (https://github.com/sympy/sympy)
-   .../projects/sympy/sympy/solvers/diophantine/diophantine.py:176:44 - error: Cannot access attribute "expand" for class "Basic"
-     Attribute "expand" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:314:30 - error: Cannot access attribute "as_independent" for class "Basic"
-     Attribute "as_independent" is unknown (reportAttributeAccessIssue)
-   .../projects/sympy/sympy/solvers/diophantine/tests/test_diophantine.py:383:30 - error: Cannot access attribute "as_independent" for class "Basic"
-     Attribute "as_independent" is unknown (reportAttributeAccessIssue)
+   .../projects/sympy/sympy/solvers/ode/single.py:867:9 - error: Expression with type "tuple[ComplexInfinity | NaN | Rational | Zero | Infinity | NegativeInfinity | Float | NotImplementedType | Expr | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown]] | tuple[ComplexInfinity | NaN | Rational | Zero | Infinity | NegativeInfinity | Float | NotImplementedType | Expr | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown], list[tuple[Unknown, Unknown]] | list[Unknown]]" cannot be assigned to target tuple
+     Type "tuple[ComplexInfinity | NaN | Rational | Zero | Infinity | NegativeInfinity | Float | NotImplementedType | Expr | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown], list[tuple[Unknown, Unknown]] | list[Unknown]]" is incompatible with target tuple
+       Tuple size mismatch; expected 2 but received 3 (reportAssignmentType)
-   .../projects/sympy/sympy/solvers/ode/systems.py:1214:26 - error: Argument of type "dict[str, str | Unknown | Pow | bool | Symbol]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, str]]" in function "update"
+   .../projects/sympy/sympy/solvers/ode/systems.py:1214:26 - error: Argument of type "dict[str, str | Unknown | Expr | bool | Symbol]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, str]]" in function "update"
-   .../projects/sympy/sympy/vector/implicitregion.py:188:18 - error: Operator "/" not supported for types "int | Unknown" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "/" not supported for types "int" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/vector/implicitregion.py:189:18 - error: Operator "/" not supported for types "int | Unknown" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "/" not supported for types "int" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/vector/implicitregion.py:190:18 - error: Operator "/" not supported for types "int | Unknown" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "/" not supported for types "int" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/vector/implicitregion.py:206:18 - error: Operator "*" not supported for types "Unknown | Expr | Any" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/vector/implicitregion.py:210:18 - error: Operator "*" not supported for types "Unknown | Expr | Any" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ" (reportOperatorIssue)
-   .../projects/sympy/sympy/vector/implicitregion.py:214:18 - error: Operator "*" not supported for types "Unknown | Expr | Any" and "Alg | Unknown | GaussianRational | MPQ | GaussianInteger | MPZ | Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Infinity | NegativeInfinity | Float | Number | Poly | Any"
-     Operator "*" not supported for types "Expr" and "GaussianRational"
-     Operator "*" not supported for types "Expr" and "MPQ"
-     Operator "*" not supported for types "Expr" and "GaussianInteger"
-     Operator "*" not supported for types "Expr" and "MPZ" (reportOperatorIssue)
- 38415 errors, 84 warnings, 0 informations
+ 38407 errors, 84 warnings, 0 informations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type narrowing with subclassed descriptors

2 participants