Skip to content

Document supported TypedDict operations and methods - #6014

Merged
JukkaL merged 2 commits into
masterfrom
doc-typeddict-methods
Dec 6, 2018
Merged

JukkaL merged 2 commits into
masterfrom
doc-typeddict-methods

Conversation

@JukkaL

@JukkaL JukkaL commented Dec 5, 2018

Copy link
Copy Markdown
Collaborator

Follow-up to #6011 (this must be merged after it).

Follow-up to #6011 (this must be merged after it).
@JukkaL
JukkaL requested a review from ilevkivskyi December 5, 2018 17:04

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

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.

Comment thread 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,

Copy link
Copy Markdown
Member

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 :-)

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.)

Comment thread 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()``

Copy link
Copy Markdown
Member

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.

Comment thread 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:

Copy link
Copy Markdown
Member

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,".

Comment thread 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.

Copy link
Copy Markdown
Member

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.

Comment thread 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a note?

@JukkaL
JukkaL merged commit 58e92fe into master Dec 6, 2018
@gvanrossum
gvanrossum deleted the doc-typeddict-methods branch December 7, 2018 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants