-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Allow TypedDict to inherit from Generics #89026
Comments
TypedDict PEP-589 says: So the current implementation has: This restricts the user from defining generic TypedDicts in the natural class based syntax: Although PEP-589 doesn't explicitly state generic support, I believe it is complete in covering the specification even if generics were involved (at least for the class based syntax). I have tried putting together a PEP from guidance of typing-sig <https://github.com/sransara/py-generic-typeddict/blob/master/pep-9999.rst\>. There is not much new contributions by that draft, except for specifying the alternative syntax and being more explicit about Generics. So I'm wondering if it would be possible to relax the constraint: TypedDict inheritance to include Generic. In my point of view |
See also python/mypy#3863 |
Guido, OP has kindly written a mini PEP for this. Do you think just updating PEP-589 is sufficient, or do we need a full PEP? (PS. Changed version to 3.11 since we've missed the train for 3.10 enhancements). |
Updating an existing (standards track) PEP significantly is not On Sun, Sep 5, 2021 at 01:24 Ken Jin <report@bugs.python.org> wrote:
-- |
My initial intention to create this ticket was to explore the idea that if we could side step from creating a PEP or updating PEP-589. IMO only contribution from a new PEP will be:
I believe PEP-589 is complete in covering all semantic details even with Generics. Even structural subtyping because it says: "Value types behave invariantly, since TypedDict objects are mutable." My understanding was that during initial implementation this was not done for the sake of implementation simplicity (days before PEP-560). All that said, a new PEP would be a good way to notify the type checkers of this capability. Is there a better place to have this conversation? |
Since this primarily affects static type checkers such as mypy, Pyre and pyright, it’s best to discuss it on typing-sig. |
there's a thread on typing-sig for this now: https://mail.python.org/archives/list/typing-sig@python.org/thread/I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ/#I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ |
Related issue: https://bugs.python.org/issue43923 |
This will be in Python 3.11 (#27663). Thanks @sransara for the PR and @serhiy-storchaka, @uriyyo, @Fidget-Spinner, @davidfstr, and @sobolevn for reviewing it! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: