Special typing construct to mark a TypedDict key as potentially missing. For example:: class Movie(TypedDict): title: str year: NotRequired[int] m = Movie( title='The Matrix', # typechecker error if key is omitted year=1999,
(self, parameters)
| 3383 | |
| 3384 | @_SpecialForm |
| 3385 | def NotRequired(self, parameters): |
| 3386 | """Special typing construct to mark a TypedDict key as potentially missing. |
| 3387 | |
| 3388 | For example:: |
| 3389 | |
| 3390 | class Movie(TypedDict): |
| 3391 | title: str |
| 3392 | year: NotRequired[int] |
| 3393 | |
| 3394 | m = Movie( |
| 3395 | title='The Matrix', # typechecker error if key is omitted |
| 3396 | year=1999, |
| 3397 | ) |
| 3398 | """ |
| 3399 | item = _type_check(parameters, f'{self._name} accepts only a single type.') |
| 3400 | return _GenericAlias(self, (item,)) |
| 3401 | |
| 3402 | |
| 3403 | @_SpecialForm |