-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
bpo-44863: In TypedDict allow inherit from Generic and preserve bases #27663
Merged
JelleZijlstra
merged 40 commits into
python:main
from
sransara:py-generic-typeddict-simple
May 3, 2022
Merged
Changes from 14 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
6cfdc5f
Allow TypedDict to inherit from Generic
sransara c022e44
TypedDict preserve MRO
sransara 2fa00b8
Fix base classes to be just generic and dict
sransara b829d8a
Simplify addiotion of Generic base class
sransara c5762df
Fully proxy origin by using types.GenericAlias
sransara 4c5db0a
Add NEWS blurb
sransara 34189dd
Add better NEWS blurb
sransara 0cfd637
Add more testcases
sransara 5e808af
Add implicit any test case
sransara a2482ff
Fix issue with plain generic inheritance
sransara 071c1b6
Include bases assertion
sransara 3ce517b
Update NEWS blurb with better formatting
sransara 2f003e0
Revert overriding of getitem and not proxy dunders
sransara 964f7d3
Use alternative way to find if Generic base is needed
sransara c3c0e51
Make it clear when Generic base is included
sransara d34c99e
Add getitem:so TD is subscriptable only if Generic
sransara cea66c4
Fix test consistency for empty params
sransara 0ed4326
Test for adding new generic arg in child class
sransara b1fcd16
Update Lib/typing.py
sransara 2905f29
Merge branch 'main' into py-generic-typeddict-simple
serhiy-storchaka afa5e51
Fix merge error.
serhiy-storchaka 94138f6
Fix trailing spaces.
serhiy-storchaka 2572930
Merge branch 'main' into py-generic-typeddict-simple
serhiy-storchaka c2e1d8d
Fix indentation
sransara d3d9456
Remove trailing commas in tuples
sransara 311852c
Add test with flipped bases
sransara dc98753
Move implicit any test to on its own case
sransara 9bed1d4
Add checks for orig_bases and mro
sransara 6c152e7
Remove specialization from generic get_type_hints
sransara f88201b
Check type hints of inherited generic typeddict
sransara 6ea95df
Remove unused statement
sransara 80e9104
Add class method through the metaclass
sransara dbbb707
Fix generic base when inherited from implicit any
sransara 56b69e0
Fix whitespacing with reindent.py
sransara 4a40825
fix tuple
JelleZijlstra 4b50ae2
remove unnecessary __class_getitem__ override
JelleZijlstra ecc7726
Merge remote-tracking branch 'upstream/main' into py-generic-typeddic…
JelleZijlstra 5b5a983
docs
JelleZijlstra 99a1430
Merge branch 'main' into py-generic-typeddict-simple
JelleZijlstra 79c2bb4
Merge branch 'main' into py-generic-typeddict-simple
JelleZijlstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Library/2021-09-03-07-56-48.bpo-44863.udgz95.rst
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Allow :class:`~typing.TypedDict` subclasses to also include | ||
:class:`~typing.Generic` as a base class in class based syntax. Thereby allowing | ||
the user to define a generic ``TypedDict``, just like a user-defined generic but | ||
with ``TypedDict`` semantics. |
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.
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 test
get_type_hints(BarGeneric[int])
?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.
This is related to the previous discussion here: #27663 (comment)
__annotations__
is not proxied by_GenericAlias
. All dunder values are not proxied by_GenericAlias
. This commit reverted the previous implementation that did what you are suggesting.I will check to see if there's a way to get the best of both worlds by using
_GenericAlias
and overridinggetattr
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.
@JelleZijlstra @davidfstr Actually the currently implemented behavior is similar to how normal generic classes behave as shown below. So I just modified the
test_get_type_hints_generic
test case a bit. Can you please take a look?