You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: peps/pep-0705.rst
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -312,20 +312,28 @@ Inheritance
312
312
313
313
To avoid potential confusion, it is an error to have a read-only type extend a non-read-only type::
314
314
315
+
class BandAndAlbum(TypedDict):
316
+
band: str
317
+
album: ReadOnly[Album]
318
+
315
319
class BandAlbumAndLabel(BandAndAlbum, readonly=True): # Runtime error
316
320
label: str
317
321
318
322
319
323
It is also an error to have a type without ``other_keys`` specified extend a type with ``other_keys=Never``::
320
324
321
-
class NamedDict(TypedDict, readonly=True):
325
+
class Building(TypedDict, other_keys=Never):
322
326
name: str
327
+
address: str
323
328
324
-
class Person(NamedDict): # Runtime error
325
-
age: float
329
+
class Museum(Building): # Runtime error
330
+
pass
326
331
327
332
It is valid to have a non-read-only type extend a read-only one. The subclass will not be read-only, but any keys not redeclared in the subclass will remain read-only::
0 commit comments