Skip to content
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

False positive with typing.TypedDict? #120

Closed
yakMM opened this issue Nov 21, 2022 · 7 comments · Fixed by #121
Closed

False positive with typing.TypedDict? #120

yakMM opened this issue Nov 21, 2022 · 7 comments · Fixed by #121
Labels
bug Something isn't working

Comments

@yakMM
Copy link
Contributor

yakMM commented Nov 21, 2022

Consider the following:

from typing import TypedDict

foo = TypedDict("foo", {"bar": str})


class Foo(TypedDict):
    bar: str

slotscheck running in stric mode (require-subclass = true) will flag both foo and Foo as missing slots, although TypedDict are not used as "real class" and don't support slots:

PS D:\test> slotscheck main.py -v
ERROR: 'main:Foo' has no slots, but it could have.
       This is flagged because the strict `require-subclass` setting is active.
ERROR: 'main:foo' has no slots, but it could have.
       This is flagged because the strict `require-subclass` setting is active.
Oh no, found some problems!

Or should TypedDict support slots out of the box?

@yakMM yakMM changed the title False positive with typing.TypedDict False positive with typing.TypedDict? Nov 21, 2022
@ariebovenberg
Copy link
Owner

@yakMM thanks for reporting, I'll have a look 👀

@ariebovenberg
Copy link
Owner

Did some digging:

>>> foo.__bases__
(<class 'dict'>, )

because dict has slots, the require-subclass setting is activated. However, since typeddicts aren't 'real' classes (type(foo()) == dict) there should be a special exception in slotscheck.

@ariebovenberg ariebovenberg added the bug Something isn't working label Nov 21, 2022
@yakMM
Copy link
Contributor Author

yakMM commented Nov 21, 2022

Thanks a lot, that was a fast fix 😍

@ItsDrike
Copy link

ItsDrike commented Mar 1, 2023

This should also be ignored for the backported typing_extensions.TypedDict, not just for typing.TypedDict

@ariebovenberg
Copy link
Owner

@ItsDrike good catch! I'll have a look.

@ariebovenberg
Copy link
Owner

@ItsDrike version 0.16.5 is now out with the fix

@ItsDrike
Copy link

ItsDrike commented Mar 1, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants