Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ def _verify_disjoint_base(
if stub.is_final:
return
is_disjoint_runtime = _is_disjoint_base(runtime)
if is_disjoint_runtime and not stub.is_disjoint_base:
# Don't complain about missing @disjoint_base if there are __slots__, because
# in that case we can infer that it's a disjoint base.
if is_disjoint_runtime and not stub.is_disjoint_base and not runtime.__dict__.get("__slots__"):
Copy link
Member

@AlexWaygood AlexWaygood Aug 21, 2025

Choose a reason for hiding this comment

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

if it's a disjoint base at runtime because it has __slots__, maybe we could change the error message to say "has __slots__ at runtime (making it a disjoint base), but doesn't have __slots__ in the stub"? And ideally tell the user what the __slots__ are at runtime.

Otherwise I worry we'll have contributors adding @disjoint_base to the stubs because a stubtest error message told them to, when actually they should be adding __slots__

Copy link
Member Author

Choose a reason for hiding this comment

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

The code now doesn't make you add @disjoint_base if there are __slots__. Instead stubtest (somewhere else) should just directly tell you to add __slots__.

Copy link
Member

Choose a reason for hiding this comment

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

ohh, I see, sorry! I misread

yield Error(
object_path,
"is a disjoint base at runtime, but isn't marked with @disjoint_base in the stub",
Expand Down
25 changes: 25 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,31 @@ class BytesEnum(bytes, enum.Enum):
""",
error=None,
)
yield Case(
stub="""
class HasSlotsAndNothingElse:
__slots__ = ("x",)
x: int

class HasInheritedSlots(HasSlotsAndNothingElse):
pass

class HasEmptySlots:
__slots__ = ()
""",
runtime="""
class HasSlotsAndNothingElse:
__slots__ = ("x",)
x: int

class HasInheritedSlots(HasSlotsAndNothingElse):
pass

class HasEmptySlots:
__slots__ = ()
""",
error=None,
)

@collect_cases
def test_decorator(self) -> Iterator[Case]:
Expand Down
Loading