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)
| 3434 | |
| 3435 | @_SpecialForm |
| 3436 | def NotRequired(self, parameters): |
| 3437 | """Special typing construct to mark a TypedDict key as potentially missing. |
| 3438 | |
| 3439 | For example:: |
| 3440 | |
| 3441 | class Movie(TypedDict): |
| 3442 | title: str |
| 3443 | year: NotRequired[int] |
| 3444 | |
| 3445 | m = Movie( |
| 3446 | title='The Matrix', # typechecker error if key is omitted |
| 3447 | year=1999, |
| 3448 | ) |
| 3449 | """ |
| 3450 | item = _type_check(parameters, f'{self._name} accepts only a single type.') |
| 3451 | return _GenericAlias(self, (item,)) |
| 3452 | |
| 3453 | |
| 3454 | @_SpecialForm |
searching dependent graphs…