-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
final TypedDict with total=False does not allow clear/popitem #14914
Comments
Kiiiiiind of a duplicate of #7981, in that mypy doesn't currently have any special handling for |
Actually it does now! See #13838 |
Oh my bad! Thank you! |
What return type should
Normally it would have to be the first one, but because the TypedDict is final, we know the complete possible set of key/value types. The third would be the most accurate but also the most costly to work with and hardest to read if any errors came up. |
I'd personally go with option (2). Silently inferring |
Bug Report
PEP-589 disallows clear and popitem on TypedDicts, even if all known keys are not required, as there may be other required keys due to structural subtyping. However, a
@final
-decorated TypedDict cannot be structurally subtyped, so these methods should be available.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=7d42af8206cb1e25a53673bdf4e99df1
Expected Behavior
No errors
Actual Behavior
Your Environment
The text was updated successfully, but these errors were encountered: