[issue44863] Allow TypedDict to inherit from Generics

2021-09-06 Thread Samodya Abey


Samodya Abey  added the comment:

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?

--

___
Python tracker 
<https://bugs.python.org/issue44863>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44863] Allow TypedDict to inherit from Generics

2021-08-07 Thread Samodya Abey


New submission from Samodya Abey :

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-.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?

--
components: Library (Lib)
messages: 399201
nosy: sransara
priority: normal
severity: normal
status: open
title: Allow TypedDict to inherit from Generics
type: enhancement
versions: Python 3.10, Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44863>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com