Repository navigation
Document supported TypedDict operations and methods - #6014
Merged
Merged
Conversation
Follow-up to #6011 (this must be merged after it).
ilevkivskyi
approved these changes
Dec 5, 2018
ilevkivskyi
left a comment
Member
There was a problem hiding this comment.
Thanks! Just one small suggestion.
|
|
||
| TypedDict objects support a subset of dictionary operations and methods: | ||
|
|
||
| * Anything included in the mapping protocol, such as indexing, |
Member
There was a problem hiding this comment.
I would rather just say in collections.abc.Mapping, since it is not a protocol :-)
gvanrossum
reviewed
Dec 5, 2018
gvanrossum
left a comment
Member
There was a problem hiding this comment.
(Some comments I failed to send before.)
| TypedDict objects support a subset of dictionary operations and methods: | ||
|
|
||
| * Anything included in the mapping protocol, such as indexing, | ||
| ``get()``, ``keys()`` and ``items()`` |
Member
There was a problem hiding this comment.
Why not provide the full list here.
| * ``pop(k[, default])`` (partial TypedDicts only) | ||
| * ``del d[k]`` (partial TypedDicts only) | ||
|
|
||
| These methods are also supported in Python 2 code: |
Member
There was a problem hiding this comment.
I'd lead with "In Python 2 code,".
| * ``viervalues()`` | ||
|
|
||
| You must use string literals as keys when calling most of the above methods, | ||
| as otherwise mypy won't be able to check that the key is valid. |
Member
There was a problem hiding this comment.
Wonder if this doesn't deserve placement at the top of this section. It's pretty important.
|
|
||
| ``clear()`` and ``popitem()`` are not supported since they are unsafe | ||
| -- they could delete required TypedDict items that are not visible to | ||
| mypy because of structural subtyping. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #6011 (this must be merged after it).