Skip to content

TypedDict and del #3550

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

Closed
JukkaL opened this issue Jun 15, 2017 · 0 comments
Closed

TypedDict and del #3550

JukkaL opened this issue Jun 15, 2017 · 0 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 15, 2017

Mypy disallows del td[key] for typed dicts. However, it should be okay to delete a key from typed dict if the key exists and it's not a required key. del with a non-literal key should always be rejected.

@JukkaL JukkaL self-assigned this Nov 16, 2018
JukkaL added a commit that referenced this issue Dec 6, 2018
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant