Repository navigation
Implement PEP 800 disjoint-base semantics - #11593
Conversation
Co-authored-by: Copilot App <[email protected]>
|
🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR. |
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
- Preserve disjoint-base conflict diagnostics when an unknown base is present - Extract shared most-derived reduction into ClassType.getMostDerivedDisjointBase - Add regression coverage for the unknown-base conflict case Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <[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.
Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
getDisjointBase previously returned undefined for any class whose MRO contained Any/Unknown, which discarded known disjoint bases inherited transitively (e.g. class C(Weird, Right) where Weird(Left, unresolved)). An unknown class cannot make two already-known disjoint bases compatible, so the most-derived known candidate is now preserved and transitive conflicts are still reported. Adds a regression case. Co-authored-by: Copilot <[email protected]>
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
object is a disjoint base but is compatible with every other disjoint base, so including it in the reported incompatible-base names (e.g. class C(Left, Plain, Right)) is misleading. Filter it out of the message. Added a regression sample and bumped the expected error count. Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Preserve known disjoint bases across unknown inheritance, model runtime slots accurately, and cover unknown and slotted edge cases. Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Co-authored-by: Copilot <[email protected]>
|
The supplied diff includes changes already present on main; please rebase so the PR reflects only its actual disjoint-base delta. |
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Avoid forcing deferred dataclass method synthesis during slot classification and keep KW_ONLY handling consistent across synthesis paths. Co-authored-by: Copilot App <[email protected]>
…joint-base Co-authored-by: Copilot <[email protected]> # Conflicts: # packages/pyright-internal/src/analyzer/scope.ts
|
Diff from mypy_primer, showing the effect of this PR on open source code: ibis (https://github.com/ibis-project/ibis)
+ .../projects/ibis/ibis/common/collections.py:281:7 - error: Base classes have incompatible disjoint bases: "dict", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_grounds.py:185:7 - error: Base classes have incompatible disjoint bases: "int", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_grounds.py:191:7 - error: Base classes have incompatible disjoint bases: "float", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_grounds.py:203:7 - error: Base classes have incompatible disjoint bases: "int", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_grounds.py:209:7 - error: Base classes have incompatible disjoint bases: "float", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:273:11 - error: Base classes have incompatible disjoint bases: "str", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:288:11 - error: Base classes have incompatible disjoint bases: "int", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:486:11 - error: Base classes have incompatible disjoint bases: "list", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:1141:11 - error: Base classes have incompatible disjoint bases: "float", "Abstract" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:1211:7 - error: Base classes have incompatible disjoint bases: "Abstract", "list" (reportGeneralTypeIssues)
+ .../projects/ibis/ibis/common/tests/test_patterns.py:1238:11 - error: Base classes have incompatible disjoint bases: "int", "Abstract" (reportGeneralTypeIssues)
- 7521 errors, 260 warnings, 0 informations
+ 7532 errors, 260 warnings, 0 informations
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/nonhomogeneous.py:225:45 - error: Cannot access attribute "has" for class "tuple[Expr, int]"
+ Attribute "has" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:223:22 - error: No overloads for "__new__" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:223:25 - error: Argument of type "CRootOf | tuple[Expr, int]" cannot be assigned to parameter "arg" of type "Expr" in function "__new__"
- Type "CRootOf | tuple[Expr, int]" is not assignable to type "Expr"
- "tuple[Expr, int]" is not assignable to "Expr" (reportArgumentType)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:238:40 - error: No overloads for "__new__" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:238:50 - error: Argument of type "CRootOf | tuple[Expr, int]" cannot be assigned to parameter "arg" of type "Expr" in function "__new__"
- Type "CRootOf | tuple[Expr, int]" is not assignable to type "Expr"
- "tuple[Expr, int]" is not assignable to "Expr" (reportArgumentType)
- .../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: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: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)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3501:18 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3501:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3502:9 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3502:16 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3502:24 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
... (truncated 1342 lines) ...
steam.py (https://github.com/Gobot1234/steam.py)
+ .../projects/steam.py/steam/ext/csgo/backpack.py:273:7 - error: Base classes have incompatible disjoint bases: "Asset", "_BaseInspectedItem" (reportGeneralTypeIssues)
+ .../projects/steam.py/steam/ext/csgo/backpack.py:291:7 - error: Base classes have incompatible disjoint bases: "Asset", "BaseItem" (reportGeneralTypeIssues)
+ .../projects/steam.py/steam/store.py:304:7 - error: Base classes have incompatible disjoint bases: "StoreItem", "PartialApp" (reportGeneralTypeIssues)
+ .../projects/steam.py/steam/store.py:310:7 - error: Base classes have incompatible disjoint bases: "StoreItem", "PartialPackage" (reportGeneralTypeIssues)
+ .../projects/steam.py/steam/store.py:316:7 - error: Base classes have incompatible disjoint bases: "StoreItem", "Bundle" (reportGeneralTypeIssues)
- 8299 errors, 87 warnings, 0 informations
+ 8304 errors, 87 warnings, 0 informations
|
|
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/types.ts:L713.
[verified] |
|
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/scope.ts:L272.
[verified] |
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
| classType.shared.hasNonEmptySlots = localSlotsNames.length > 0; | ||
| } | ||
|
|
||
| // Validates fields for compatibility with a dataclass and synthesizes |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
localSlotsNames and hasNonEmptySlots are now computed independently here and in synthesizeDataClassMethods, with different exclusion rules. Because both are guarded by === undefined, whichever path runs first determines the result, making slot behavior potentially evaluation-order dependent. Please consolidate the filtering logic or add coverage proving both paths produce identical results for KW_ONLY, ClassVar, InitVar, and inherited-field cases.
[verified]
Stella Huang (StellaHuang95)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Summary
@disjoint_basemetadata and implicit disjoint bases from nonempty__slots__, including synthesized dataclass slots@disjoint_baseon functions, TypedDict classes, and Protocol classes with targeted diagnosticsTests
npx jest typeEvaluator6.test --runInBand -t "DisjointBase1" --forceExitnpm run buildinpackages/pyright-internalnpm run typecheck