Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
mypy/stubtest.py Outdated
| ifis_disjoint_runtimeandnotstub.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. | ||
| ifis_disjoint_runtimeandnotstub.is_disjoint_baseandstub.slotsisNone: |
There was a problem hiding this comment.
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:
>>>classFoo:...__slots__= ()... >>>classBar:...__slots__= ()... >>>classBaz(Foo,Bar):......
does this logic account for that?
JelleZijlstraAug 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
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.
| ifis_disjoint_runtimeandnotstub.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. | ||
| ifis_disjoint_runtimeandnotstub.is_disjoint_baseandnotruntime.__dict__.get("__slots__"): |
AlexWaygoodAug 21, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
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__
There was a problem hiding this comment.
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__.
There was a problem hiding this comment.
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
30a5263 intopython:masterUh oh!
There was an error while loading.Please reload this page.
No description provided.