Skip to content

Implement PEP 800 disjoint-base semantics - #11593

Merged
Rich Chiodo (rchiodo) merged 12 commits into
mainfrom
rchiodo-implement-disjoint-base
Aug 10, 2026
Merged

Rich Chiodo (rchiodo) merged 12 commits into
mainfrom
rchiodo-implement-disjoint-base

Conversation

@rchiodo

@rchiodo Rich Chiodo (rchiodo) commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • recognize explicit @disjoint_base metadata and implicit disjoint bases from nonempty __slots__, including synthesized dataclass slots
  • propagate effective disjoint bases through inheritance and reject class definitions with unrelated candidate bases
  • reject @disjoint_base on functions, TypedDict classes, and Protocol classes with targeted diagnostics
  • add upstream-derived PEP 800 conformance coverage for nominal classes, NamedTuple, inherited bases, slots, and invalid decorator targets

Tests

  • npx jest typeEvaluator6.test --runInBand -t "DisjointBase1" --forceExit
  • npm run build in packages/pyright-internal
  • npm run typecheck
  • targeted class, Protocol, TypedDict, NamedTuple, slots, and dataclass-slots regression tests (isinstance narrowing for disjoint bases is intentionally deferred to a follow-up)
  • targeted ESLint and Prettier checks

@StellaHuang95

Stella Huang (StellaHuang95) commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@StellaHuang95 Stella Huang (StellaHuang95) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 6, 2026
- 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]>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:changes-requested Automated review: posted blocking findings to address. and removed review-auto:approved Automated review: no blocking findings (approval posted). labels Aug 7, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

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]>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:approved Automated review: no blocking findings (approval posted). and removed review-auto:changes-requested Automated review: posted blocking findings to address. labels Aug 7, 2026
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@StellaHuang95

Copy link
Copy Markdown
Collaborator

The supplied diff includes changes already present on main; please rebase so the PR reflects only its actual disjoint-base delta.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

Rich Chiodo (rchiodo) and others added 2 commits August 10, 2026 11:59
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
@github-actions

Copy link
Copy Markdown
Contributor

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

@rchiodo
Rich Chiodo (rchiodo) merged commit 30e8470 into main Aug 10, 2026
20 checks passed
@StellaHuang95

Copy link
Copy Markdown
Collaborator

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.

Info · Optional note

ClassDetailsShared.hasNonEmptySlots is optional while Scope.hasNonEmptySlots defaults to false; typeEvaluator.ts can therefore assign undefined and relies on coercion at the current read site. Please make the shared representation consistently non-optional with a false default to avoid future direct reads treating the state inconsistently.

[verified]

@StellaHuang95

Copy link
Copy Markdown
Collaborator

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.

Info · Optional note

hasNonEmptySlots is exposed as a public mutable field but also has a setter, while the sibling slotsNames uses direct field access. Please choose one convention (for example, add a getter and encapsulate the field, or remove the setter) so the new state has a single, clear access pattern.

[verified]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

classType.shared.hasNonEmptySlots = localSlotsNames.length > 0;
}

// Validates fields for compatibility with a dataclass and synthesizes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

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

Labels

review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants