@@ -115,9 +115,6 @@ any :term:`typing:type qualifier` can be used for individual fields::
115
115
Inlined typed dictionaries are implicitly *total *, meaning all keys must be
116
116
present. Using the :data: `~typing.Required ` type qualifier is thus redundant.
117
117
118
- If :pep: `728 ` gets accepted, inlined typed dictionaries will be implicitly
119
- :ref: `closed <typed-dict-closed >`.
120
-
121
118
Type variables are allowed in inlined typed dictionaries, provided that they
122
119
are bound to some outer scope::
123
120
@@ -137,15 +134,12 @@ are bound to some outer scope::
137
134
138
135
T = TypeVar('T')
139
136
140
- InlinedTD = TypedDict[{'name': T}] # Not OK, `T` refers to a type variable that is not bound to any scope.
141
-
137
+ InlinedTD = TypedDict[{'name': T}] # OK, same as the previous type alias, but using the old-style syntax.
142
138
143
- It is not possible for an inlined typed dictionary to be extended::
144
139
145
- InlinedTD = TypedDict[{'a': int}]
140
+ def func():
141
+ InlinedTD = TypedDict[{'name': T}] # Not OK: `T` refers to a type variable that is not bound to the scope of `func`.
146
142
147
- class SubTD(InlinedTD): # Not allowed
148
- pass
149
143
150
144
Typing specification changes
151
145
----------------------------
@@ -304,8 +298,8 @@ As inlined typed dictionaries are meant to only support a subset of the
304
298
existing syntax, adding this extension mechanism isn't compelling
305
299
enough to be supported, considering the added complexity.
306
300
307
- If intersections were to be added into the type system, it would most
308
- likely cover this use case.
301
+ If intersections were to be added into the type system, it could cover this
302
+ use case.
309
303
310
304
311
305
Open Issues
@@ -328,6 +322,23 @@ implementation to provide the introspection attributes (such as
328
322
:attr: `~typing.TypedDict.__total__ `), and tools relying on runtime
329
323
introspection would have to add proper support for this new type.
330
324
325
+ Depending on the outcome of the runtime implementation, we can more or less
326
+ easily allow extending inlined typed dictionaries::
327
+
328
+ InlinedTD = TypedDict[{'a': int}]
329
+
330
+ # If `InlinedTD` is a typing._InlinedTypedDict instance, this adds complexity:
331
+ class SubTD(InlinedTD):
332
+ pass
333
+
334
+ Inlined typed dictionaries and extra items
335
+ ------------------------------------------
336
+
337
+ :pep: `728 ` introduces the concept of :ref: `closed <typed-dict-closed >` type
338
+ dictionaries. If this PEP were to be accepted, inlined typed dictionaries
339
+ will be *closed * by default. This means :pep: `728 ` needs to be addressed
340
+ first, so that this PEP can be updated accordingly.
341
+
331
342
332
343
Copyright
333
344
=========
0 commit comments