-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
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! |
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 left a few minor wording comments
pep-0589.rst
Outdated
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.
definition
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
Remove this copy of the file?
FYI @JukkaL you're flagged as having not signed the CLA and CI failed. |
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 |
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.
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.
First draft.