-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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: |
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:
>>> class Foo:
... __slots__ = ()
...
>>> class Bar:
... __slots__ = ()
...
>>> class Baz(Foo, Bar): ...
...
does this logic account for that?
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.
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__"): |
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
No description provided.