Special typing construct to mark a TypedDict key as required. This is mainly useful for total=False TypedDicts. For example:: class Movie(TypedDict, total=False): title: Required[str] year: int m = Movie( title='The Matrix', # typechec
(self, parameters)
| 3410 | |
| 3411 | @_SpecialForm |
| 3412 | def Required(self, parameters): |
| 3413 | """Special typing construct to mark a TypedDict key as required. |
| 3414 | |
| 3415 | This is mainly useful for total=False TypedDicts. |
| 3416 | |
| 3417 | For example:: |
| 3418 | |
| 3419 | class Movie(TypedDict, total=False): |
| 3420 | title: Required[str] |
| 3421 | year: int |
| 3422 | |
| 3423 | m = Movie( |
| 3424 | title='The Matrix', # typechecker error if key is omitted |
| 3425 | year=1999, |
| 3426 | ) |
| 3427 | |
| 3428 | There is no runtime checking that a required key is actually provided |
| 3429 | when instantiating a related TypedDict. |
| 3430 | """ |
| 3431 | item = _type_check(parameters, f'{self._name} accepts only a single type.') |
| 3432 | return _GenericAlias(self, (item,)) |
| 3433 | |
| 3434 | |
| 3435 | @_SpecialForm |
searching dependent graphs…