@@ -240,7 +240,12 @@ The ``closed`` Class Parameter
240240------------------------------
241241
242242When neither ``extra_items `` nor ``closed=True `` is specified, ``closed=False ``
243- is assumed.
243+ is assumed. The TypedDict should allow non-required extra items of value type
244+ ``ReadOnly[object] `` during inheritance or assignability checks, to
245+ preserve the default TypedDict behavior. Extra keys included in TypedDict
246+ object construction should still be caught, as mentioned in TypedDict's
247+ `typing spec
248+ <https://typing.python.org/en/latest/spec/typeddict.html#supported-and-unsupported-operations.> `__.
244249
245250When ``closed=True `` is set, no extra items are allowed. This is equivalent to
246251``extra_items=Never ``, because there can't be a value type that is assignable to
@@ -293,13 +298,6 @@ argument is a read-only type::
293298This will be further discussed in
294299:ref: `a later section <pep728-inheritance-read-only >`.
295300
296- The TypedDict should allow non-required extra items of value type
297- ``ReadOnly[object] `` during inheritance or assignability checks, to
298- preserve the default TypedDict behavior. Extra keys included in TypedDict
299- object construction should still be caught, as mentioned in TypedDict's
300- `typing spec
301- <https://typing.python.org/en/latest/spec/typeddict.html#supported-and-unsupported-operations.> `__.
302-
303301``closed `` is also supported with the functional syntax::
304302
305303 Movie = TypedDict("Movie", {"name": str}, closed=True)
@@ -331,13 +329,21 @@ For type checking purposes, ``Unpack[SomeTypedDict]`` with extra items should be
331329treated as its equivalent in regular parameters, and the existing rules for
332330function parameters still apply::
333331
334- class Movie (TypedDict, extra_items=int ):
332+ class MovieNoExtra (TypedDict):
335333 name: str
336334
337- def f(**kwargs: Unpack[Movie]) -> None: ...
335+ class MovieExtra(TypedDict, extra_items=int):
336+ name: str
337+
338+ def f(**kwargs: Unpack[MovieNoExtra]) -> None: ...
339+ def g(**kwargs: Unpack[MovieExtra]) -> None: ...
338340
339341 # Should be equivalent to:
340- def f(*, name: str, **kwargs: int) -> None: ...
342+ def f(*, name: str) -> None: ...
343+ def g(*, name: str, **kwargs: int) -> None: ...
344+
345+ f(name="No Country for Old Men", year=2007) # Not OK. Unrecognized item
346+ g(name="No Country for Old Men", year=2007) # OK
341347
342348Interaction with Read-only Items
343349--------------------------------
0 commit comments