8000 PEP 589: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys by JukkaL · Pull Request #956 · python/peps · GitHub
[go: up one dir, main page]

Skip to content

PEP 589: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys #956

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

Merged
merged 8 commits into from
Mar 29, 2019

Conversation

JukkaL
Copy link
Contributor
@JukkaL JukkaL commented Mar 28, 2019

First draft.

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

Copy link
Member
@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

I left a few minor wording comments

pep-0589.rst Outdated
Class-based Syntax ------------------
A TypedDict type can be defined using the class defition syntax with
Copy link
Member

Choose a reason for hiding this comment

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

definition

Suggested change
A TypedDict type can be defined using the class defition syntax with
A TypedDict type can be defined using the class definition syntax with

pep-0589.rst Outdated
``Movie`` is a TypedDict type with two items: ``'name'`` (with type
``str``) and ``'year'`` (with type ``int``).

A type checker should validate that the body a class-based TypedDict
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
A type checker should validate that the body a class-based TypedDict
A type checker should validate that the body of a class-based TypedDict

pep-0589.rst Outdated
definition conforms to these rules:

* The class body should only contain an optional docstring, followed
by lines with item definitions of form ``key: value_type``. The
10000
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
by lines with item definitions of form ``key: value_type``. The
by lines with item definitions of the form ``key: value_type``. The

pep-0589.rst Outdated
class Strings(TypedDict):
items: List[str]

print(isinstance({'items': [1]})) # Should be False
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(isinstance({'items': [1]})) # Should be False
print(isinstance({'items': [1]}, Strings)) # Should be False

pep-0589.rst Outdated
items: List[str]

print(isinstance({'items': [1]})) # Should be False
print(isinstance({'items': ['x']})) # Should be True
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print(isinstance({'items': ['x']})) # Should be True
print(isinstance({'items': ['x']}, Strings)) # Should be True

pep-0589.rst Outdated
-----------

It is possible to inherit from one or more TypedDict types using the
class-based syntax. A single class cannot inherit from both a
Copy link
Member

Choose a reason for hiding this comment

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

The second sentence of the paragraph feels a bit out of place; it sounds like the example is going to be of inheritance from a TypedDict and a non-TypedDict.

pep-0589.rst Outdated
'year': int}, total=False)

The semantics are equivalent to the class-based syntax. This syntax
doesn't support inheritance, however, and there is no way to way to
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
doesn't support inheritance, however, and there is no way to way to
doesn't support inheritance, however, and there is no way to

pep-9999.rst Outdated
@@ -0,0 +1,645 @@
PEP: 589
Copy link
Member

Choose a reason for hiding this comment

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

Remove this copy of the file?

@brettcannon
Copy link
Member

FYI @JukkaL you're flagged as having not signed the CLA and CI failed.

@gvanrossum gvanrossum merged commit 0db9dcb into python:master Mar 29, 2019
Title: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys
Author: Jukka Lehtosalo <jukka.lehtosalo@iki.fi>
Sponsor: Guido van Rossum <guido@python.org>
Discussions-To: typing-sig@python.org
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this has not been posted to typing-sig yet. I think this looks very solid and is ready to be posted there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0