Typing and Generics
typing.NotRequired
Marks a TypedDict key as omittable regardless of the enclosing total=True default. A missing key differs from an existing key with a None value. Added in 3.11.
Formal Syntax & Structure
python syntaxpython
typing.NotRequired[T]Return Value
type qualifier
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import NotRequired, TypedDict
class Job(TypedDict): id: int note: NotRequired[str]item: Job = {'id':1}print(('note' in item, sorted(Job.__optional_keys__)))