Issue44863
Created on 2021-08-07 19:04 by sransara, last changed 2022-04-11 14:59 by admin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 27663 | open | python-dev, 2021-08-07 19:05 | |
| Messages (8) | |||
|---|---|---|---|
| msg399201 - (view) | Author: Samodya Abey (sransara) * | Date: 2021-08-07 19:04 | |
TypedDict PEP-589 says: A TypedDict cannot inherit from both a TypedDict type and a non-TypedDict base class. So the current implementation has: `if type(base) is not _TypedDictMeta: raise TypeError(...)` This restricts the user from defining generic TypedDicts in the natural class based syntax: `class Pager(TypedDict, Generic[T]): ...` 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 `Generic` is more of a mixin, so it doesn't go against the PEP 589. Or is this change big enough to warrant a PEP? |
|||
| msg399579 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2021-08-14 00:58 | |
See also https://github.com/python/mypy/issues/3863 |
|||
| msg401077 - (view) | Author: Ken Jin (kj) * ![]() |
Date: 2021-09-05 08:23 | |
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). |
|||
| msg401087 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2021-09-05 14:48 | |
Updating an existing (standards track) PEP significantly is not traditional. I recommend writing a new PEP. On Sun, Sep 5, 2021 at 01:24 Ken Jin <report@bugs.python.org> wrote: > > Ken Jin <kenjin4096@gmail.com> added the comment: > > 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). > > ---------- > versions: -Python 3.10 > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue44863> > _______________________________________ > -- --Guido (mobile) |
|||
| msg401134 - (view) | Author: Samodya Abey (sransara) * | Date: 2021-09-06 12:18 | |
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: 1. relaxing this line from PEP-589 and be explicit to include Generic: "A TypedDict cannot inherit from both a TypedDict type and a non-TypedDict base class." (IMO by thinking `Generic` as a mixin even this is not needed) 2. may be syntax for generic in the alternative syntax (side note: collecting typevars from the values is hard to implement because of forward refs) 3. Some explicit generic examples for good measure 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? |
|||
| msg401138 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2021-09-06 14:52 | |
Since this primarily affects static type checkers such as mypy, Pyre and pyright, it’s best to discuss it on typing-sig. |
|||
| msg412439 - (view) | Author: Thomas Grainger (graingert) * | Date: 2022-02-03 12:34 | |
there's a thread on typing-sig for this now: https://mail.python.org/archives/list/typing-sig@python.org/thread/I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ/#I7P3ER2NH7SENVMIXK74U6L4Z5JDLQGZ |
|||
| msg414631 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2022-03-07 00:48 | |
Related issue: https://bugs.python.org/issue43923 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:48 | admin | set | github: 89026 |
| 2022-03-07 00:48:26 | rhettinger | set | nosy:
+ rhettinger messages: + msg414631 |
| 2022-03-07 00:10:20 | cdce8p | set | nosy:
+ cdce8p |
| 2022-03-05 09:57:32 | AlexWaygood | set | nosy:
+ JelleZijlstra, sobolevn |
| 2022-03-05 09:56:27 | AlexWaygood | set | nosy:
+ AlexWaygood |
| 2022-03-05 09:07:17 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka |
| 2022-02-03 12:34:15 | graingert | set | nosy:
+ graingert messages: + msg412439 |
| 2021-09-06 14:52:29 | gvanrossum | set | messages: + msg401138 |
| 2021-09-06 12:18:14 | sransara | set | messages: + msg401134 |
| 2021-09-05 14:48:32 | gvanrossum | set | messages: + msg401087 |
| 2021-09-05 08:23:30 | kj | set | messages:
+ msg401077 versions: - Python 3.10 |
| 2021-08-18 05:45:01 | toburger | set | nosy:
+ toburger |
| 2021-08-14 00:58:11 | gvanrossum | set | messages: + msg399579 |
| 2021-08-13 22:25:55 | terry.reedy | set | nosy:
+ gvanrossum, kj |
| 2021-08-07 19:05:52 | python-dev | set | keywords:
+ patch nosy: + python-dev pull_requests:
+ pull_request26152 |
| 2021-08-07 19:04:47 | sransara | create | |
