PEP 728: TypedDict with Typed Extra Items

Has the possibility of inhering from dict[str, T] been considered, similar to how TypedDict inheritance was relaxed to allow defining TypedDicts with generic values? This would also pave the way for mapping intersections (mentioned in the PEP), with

class Foo(TypedDict, dict[str, int]):
    bar: str

being equivalent to e.g. a prospective

dict[{"bar": str}] & dict[str, int]

Alternatively, how about building on PEP 696, making TypedDict itself generic, with a default value of Never:

class TypedDict[V = Never]:
    ...

class Foo(TypedDict[int]):
    bar: str

Both of these do not suffer from being difficult to port to an inline TypedDict syntax; synthesised types would emerge naturally and the extra value type would be defined statically. I personally find the extra key approach unwieldy - something that dataclass-like library authors were often forced to resort to in the past for lack of serviceable alternatives - even if we were to cleverly work around name clashes with __config__ or something like it.

1 Like