-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
TypedDict missing many dict methods #3843
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
Comments
This is already tracked in #3518, but you're listing more methods. A lot of these shouldn't be hard to do, so feel free to submit a PR. I wonder if there's also a way to inherit them from the |
I did find that ticket, but since he marked it as a feature and not a bug I figured the "special casing" refers to adding special behaviors to the listed methods (like |
It seems suspiciously like a mypy bug because typeshed should be forcing it to produce a |
I think the root of the problem is that the fallback for TypedDicts is |
Why isn't the fallback for TypedDict just Dict? |
IIRC this is because some methods of |
A user just asked about how to Note that some of the methods aren't always safe, such as |
Here's a quick analysis of each missing method:
|
This adds support for these methods through additional plugin hooks: * `pop` * `setdefault` * `update` (positional argument only) * `__delitem__` These methods also work and don't need plugin support: * `copy` * `has_key` (Python 2 only) * `viewitems` (Python 2 only) * `viewkeys` (Python 2 only) * `viewvalues` (Python 2 only) The base signatures for all of these methods are defined in `mypy_extensions._TypedDict`, which is a stub-only class only used internally by mypy. It becomes the new fallback type of all TypedDicts. Fixes #3843. Fixes #3550. There's some possible follow-up work that I'm leaving to other PRs, such as optimizing hook lookup through dictionaries in the default plugin, documenting the supported methods, and `update` with keyword arguments (#6019).
@JukkaL When can we release it? I didn't found it in latest version Thanks. |
@nguyenbathanh releases are usually done every few weeks, but due to holidays I expect it will take a bit longer between |
@ethanhs Thanks for your information! I will use the Dev version. |
mypy isn't recognizing methods of TypedDict.
The text was updated successfully, but these errors were encountered: