diff --git a/pep-0655.rst b/pep-0655.rst index b94a95ca1..dfc09274a 100644 --- a/pep-0655.rst +++ b/pep-0655.rst @@ -55,12 +55,26 @@ a mix of both required and potentially-missing keys: title: str year: NotRequired[int] +This PEP also makes it possible to define TypedDicts in the +:pep:`alternative functional syntax <589#alternative-syntax>` +with a mix of required and potentially-missing keys, +which is not currently possible at all because the alternative syntax does +not support inheritance: + +:: + + Actor = TypedDict('Actor', { + 'name': str, + # "in" is a keyword, so the functional syntax is necessary + 'in': NotRequired[List[str]], + }) + Rationale ========= One might think it unusual to propose syntax that prioritizes marking -*required* keys rather than syntax for *potentially-missing* keys, as is +*required* keys rather than *potentially-missing* keys, as is customary in other languages like TypeScript: .. code-block:: typescript @@ -139,7 +153,7 @@ same time: year: NotRequired[Required[int]] # ERROR -The :pep:`alternative syntax <589#alternative-syntax>` +The :pep:`alternative functional syntax <589#alternative-syntax>` for TypedDict also supports ``Required[]`` and ``NotRequired[]``: