File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,26 @@ a mix of both required and potentially-missing keys:
55
55
title: str
56
56
year: NotRequired[int]
57
57
58
+ This PEP also makes it possible to define TypedDicts in the
59
+ :pep: `alternative functional syntax <589#alternative-syntax >`
60
+ with a mix of required and potentially-missing keys,
61
+ which is not currently possible at all because the alternative syntax does
62
+ not support inheritance:
63
+
64
+ ::
65
+
66
+ Actor = TypedDict('Actor', {
67
+ 'name': str,
68
+ # "in" is a keyword, so the functional syntax is necessary
69
+ 'in': NotRequired[List[str]],
70
+ })
71
+
58
72
59
73
Rationale
60
74
=========
61
75
62
76
One might think it unusual to propose syntax that prioritizes marking
63
- *required * keys rather than syntax for *potentially-missing * keys, as is
77
+ *required * keys rather than *potentially-missing * keys, as is
64
78
customary in other languages like TypeScript:
65
79
66
80
.. code-block :: typescript
@@ -139,7 +153,7 @@ same time:
139
153
year: NotRequired[Required[int]] # ERROR
140
154
141
155
142
- The :pep: `alternative syntax <589#alternative-syntax >`
156
+ The :pep: `alternative functional syntax <589#alternative-syntax >`
143
157
for TypedDict also supports
144
158
``Required[] `` and ``NotRequired[] ``:
145
159
You can’t perform that action at this time.
0 commit comments