Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 stub.slots is None:
Copy link
Member

Choose a reason for hiding this comment

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

__slots__ only make a class a disjoint base if __slots__ are set to a non-empty sequence:

>>> class Foo:
...     __slots__ = ()
...     
>>> class Bar:
...     __slots__ = ()
...     
>>> class Baz(Foo, Bar): ...
...

does this logic account for that?

Copy link
Member Author

@JelleZijlstra JelleZijlstra Aug 20, 2025

Choose a reason for hiding this comment

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

Oh yes this is wrong, it also includes slots from parent classes.

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

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