-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Document supported TypedDict operations and methods #6014
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
Conversation
Follow-up to #6011 (this must be merged after it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just one small suggestion.
docs/source/more_types.rst
Outdated
|
||
TypedDict objects support a subset of dictionary operations and methods: | ||
|
||
* Anything included in the mapping protocol, such as indexing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather just say in collections.abc.Mapping
, since it is not a protocol :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Some comments I failed to send before.)
docs/source/more_types.rst
Outdated
TypedDict objects support a subset of dictionary operations and methods: | ||
|
||
* Anything included in the mapping protocol, such as indexing, | ||
``get()``, ``keys()`` and ``items()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not provide the full list here.
docs/source/more_types.rst
Outdated
* ``pop(k[, default])`` (partial TypedDicts only) | ||
* ``del d[k]`` (partial TypedDicts only) | ||
|
||
These methods are also supported in Python 2 code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd lead with "In Python 2 code,".
docs/source/more_types.rst
Outdated
* ``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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if this doesn't deserve placement at the top of this section. It's pretty important.
docs/source/more_types.rst
Outdated
|
||
``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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a note?
Follow-up to #6011 (this must be merged after it).