Skip to content

stubtest: do not require @disjoint_base if there are __slots__ #19701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2025

Conversation

JelleZijlstra
Copy link
Member

No description provided.

mypy/stubtest.py Outdated
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.

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

@JelleZijlstra JelleZijlstra merged commit 30a5263 into python:master Aug 21, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants