The proposal has been updated mainly addressing these topics:
- Spec out the
closed=Trueproposal and use__extra_items__as the special key name - Enhance the
extra=Typediscussion under the “Rejected Ideas” section - Discuss the interaction between closed vs. non-closed TypedDict.
- Note on backwards compatibility between
closedand the keyword arguments flavor of using the functional TypedDict alternative (i.e.,TD = TypedDict("TD", foo=int, bar=str, closed=SomeType)) - Use a more specific name
"__extra_items__"for the special key.
I also want to note that support for this in typing_extensions has been merged, and we are expecting to get it released in 4.10.0. This will introduce two attributes allowing runtime introspection:
-
__closed__
A boolean flag indicating whether the currentTypedDictis
considered closed.This is not inherited by the
TypedDict’s
subclasses. -
__extra_items__
The type annotation of the extra items allowed on theTypedDict.This attribute defaults to
Noneon a TypedDict that has itself and
all its bases non-closed. This default is different fromtype(None)
that represents__extra_items__: Nonedefined on a closed
TypedDict.If
__extra_items__is not defined or inherited on a closed
TypedDict, this defaults toNever.