Repository navigation
Fix defaulted subclass type specialization - #11596
Merged
Merged
Conversation
Co-authored-by: Copilot App <[email protected]>
Collaborator
|
🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR. |
Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
approved these changes
Aug 7, 2026
Stella Huang (StellaHuang95)
left a comment
Collaborator
There was a problem hiding this comment.
Approved via Review Center.
Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
approved these changes
Aug 8, 2026
Stella Huang (StellaHuang95)
left a comment
Collaborator
There was a problem hiding this comment.
Approved via Review Center.
Failure classification: B - Pyright limitation Typeshed commit: N/A Precision: Enforce concrete retained defaults while preserving inference for defaultless and gradual Any/Unknown defaults. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
approved these changes
Aug 10, 2026
Stella Huang (StellaHuang95)
left a comment
Collaborator
There was a problem hiding this comment.
Approved via Review Center.
Co-authored-by: Copilot <[email protected]>
Contributor
|
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/hypergeometric.py:247:67 - error: Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
- .../projects/sympy/sympy/solvers/ode/lie_group.py:619:61 - error: Operator "-" not supported for type "Unknown | Basic" (reportOperatorIssue)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:468:28 - error: Argument of type "Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
+ .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:468:28 - error: Argument of type "Expr | Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
- Type "Unknown | None" is not assignable to type "Expr"
+ Type "Expr | Unknown | None" is not assignable to type "Expr"
- .../projects/sympy/sympy/solvers/ode/ode.py:1433:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
+ .../projects/sympy/sympy/solvers/ode/ode.py:1433:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
- Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "Zero"
+ Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
+ .../projects/sympy/sympy/solvers/ode/ode.py:1579:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1580:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1590:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1590:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1590:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1597:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1597:64 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1603:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1603:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1603:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1610:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1610:74 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1616:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1616:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1616:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1623:49 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1623:70 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1753:36 - error: Cannot access attribute "lhs" for class "Expr"
- Attribute "lhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1753:55 - error: Cannot access attribute "rhs" for class "Expr"
- Attribute "rhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1754:36 - error: Cannot access attribute "lhs" for class "Expr"
- Attribute "lhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1755:17 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1755:17 - error: Argument of type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" cannot be assigned to parameter "value" of type "Equality | BooleanFalse | BooleanTrue" in function "__setitem__"
- Type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
- Type "Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
- "Expr" is not assignable to "Equality"
- "Expr" is not assignable to "BooleanFalse"
- "Expr" is not assignable to "BooleanTrue" (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/ode.py:2961:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
+ .../projects/sympy/sympy/solvers/ode/ode.py:2961:17 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "value" of type "Zero" in function "__setitem__"
- Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "Zero"
+ Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "Zero"
+ .../projects/sympy/sympy/solvers/ode/ode.py:3442:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3442:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3443:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3443:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3444:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3445:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3446:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3458:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3459:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3460:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3500:5 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3500:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3500:14 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
... (truncated 514 lines) ...
psycopg (https://github.com/psycopg/psycopg)
+ .../projects/psycopg/psycopg/psycopg/connection.py:78:31 - error: Cannot assign to attribute "cursor_factory" for class "Connection[Row@Connection]*"
+ "type[Cursor[TupleRow]]" is not assignable to "type[Cursor[Row@Connection]]"
+ Type "type[Cursor[Row@Cursor]]" is not assignable to type "type[Cursor[Row@Connection]]"
+ Type parameter "Row@Cursor" is covariant, but "TupleRow" is not a subtype of "Row@Connection"
+ Type "TupleRow" is not assignable to type "Row@Connection" (reportAttributeAccessIssue)
+ .../projects/psycopg/psycopg/psycopg/connection.py:79:38 - error: Cannot assign to attribute "server_cursor_factory" for class "Connection[Row@Connection]*"
+ "type[ServerCursor[TupleRow]]" is not assignable to "type[ServerCursor[Row@Connection]]"
+ Type "type[ServerCursor[Row@ServerCursor]]" is not assignable to type "type[ServerCursor[Row@Connection]]"
+ Type parameter "Row@ServerCursor" is covariant, but "TupleRow" is not a subtype of "Row@Connection"
+ Type "TupleRow" is not assignable to type "Row@Connection" (reportAttributeAccessIssue)
+ .../projects/psycopg/psycopg/psycopg/connection_async.py:82:31 - error: Cannot assign to attribute "cursor_factory" for class "AsyncConnection[Row@AsyncConnection]*"
+ "type[AsyncCursor[TupleRow]]" is not assignable to "type[AsyncCursor[Row@AsyncConnection]]"
+ Type "type[AsyncCursor[Row@AsyncCursor]]" is not assignable to type "type[AsyncCursor[Row@AsyncConnection]]"
+ Type parameter "Row@AsyncCursor" is covariant, but "TupleRow" is not a subtype of "Row@AsyncConnection"
+ Type "TupleRow" is not assignable to type "Row@AsyncConnection" (reportAttributeAccessIssue)
+ .../projects/psycopg/psycopg/psycopg/connection_async.py:83:38 - error: Cannot assign to attribute "server_cursor_factory" for class "AsyncConnection[Row@AsyncConnection]*"
+ "type[AsyncServerCursor[TupleRow]]" is not assignable to "type[AsyncServerCursor[Row@AsyncConnection]]"
+ Type "type[AsyncServerCursor[Row@AsyncServerCursor]]" is not assignable to type "type[AsyncServerCursor[Row@AsyncConnection]]"
+ Type parameter "Row@AsyncServerCursor" is covariant, but "TupleRow" is not a subtype of "Row@AsyncConnection"
+ Type "TupleRow" is not assignable to type "Row@AsyncConnection" (reportAttributeAccessIssue)
- 1936 errors, 113 warnings, 0 informations
+ 1940 errors, 113 warnings, 0 informations
scikit-learn (https://github.com/scikit-learn/scikit-learn)
- "type[ndarray[_ShapeT_co@ndarray, _DTypeT_co@ndarray]]" is not assignable to "type[coo_array[Any, tuple[Any, ...]]]"
+ "type[ndarray[_AnyShape, dtype[Any]]]" is not assignable to "type[coo_array[Any, tuple[Any, ...]]]"
- "type[ndarray[_ShapeT_co@ndarray, _DTypeT_co@ndarray]]" is not assignable to "type[coo_array[Any, tuple[Any, ...]]]"
+ "type[ndarray[_AnyShape, dtype[Any]]]" is not assignable to "type[coo_array[Any, tuple[Any, ...]]]"
|
This was referenced Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generic class values remain unspecialized so they can still be subscripted, while their
typeFormrecords the default-specialized type. Duringtype[...]assignability, Pyright was building the inheritance chain from that unspecialized class value, so absent source type arguments were treated permissively and a defaulted subclass could be accepted through the wrong specialization.When every retained class type parameter has an explicit, non-gradual default, specialize the temporary source used for class assignability with
specializeWithDefaultTypeArgs. The normal variance-aware type-argument comparison then rejects incompatibletype[...]specializations. Classes with defaultless parameters, or defaults that resolve to top-levelAny,Unknown, a gradual callable, or a gradual unpacked tuple, retain their existing unspecialized inference behavior. Structurally concrete defaults such astuple[Any, ...]remain enforceable.Coverage
Add the
generics_defaults_specialization.pyconformance case: bareChildis accepted astype[Child[str]]and rejected astype[Child[int]]when the retained base type parameter defaults tostr.Add realistic framework and library coverage for:
type[Subclass[...]]Any, unions containingAny, gradualParamSpecandTypeVarTupledefaults, and defaultless/UnknowninferenceAny, including a psycopg-styleCursor[tuple[Any, ...]]ctypes.py_object[Any]counterexamplemypy_primer audit
All eight shards completed successfully on
d72de0181.ctypes.py_objectas the only eligible bare defaulted class reached in SymPy; its directAnydefault is skipped by the final guard, so these sites have no semantic path through the new specialization. Classified as unrelated primer/run diagnostic churn, not a regression.TupleRow = tuple[Any, ...]; these are expected corrections because a bareCursor[TupleRow]is not valid for every connectionRow.Precision regression report
UnknownorAny.Tests
npx jest typeEvaluator5.test typeEvaluator8.test --runInBand --forceExit -t "TypeVarDefault|TypeForm"(25 tests)npm run buildinpackages/pyright-internalnpm run build:cli:devnpm run typechecknpm run check:eslintnpm run check:prettierctypes.py_object, mixed/defaultless inference, and nested structuralAnydefaults