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)
| 3359 | |
| 3360 | @_SpecialForm |
| 3361 | def Required(self, parameters): |
| 3362 | """Special typing construct to mark a TypedDict key as required. |
| 3363 | |
| 3364 | This is mainly useful for total=False TypedDicts. |
| 3365 | |
| 3366 | For example:: |
| 3367 | |
| 3368 | class Movie(TypedDict, total=False): |
| 3369 | title: Required[str] |
| 3370 | year: int |
| 3371 | |
| 3372 | m = Movie( |
| 3373 | title='The Matrix', # typechecker error if key is omitted |
| 3374 | year=1999, |
| 3375 | ) |
| 3376 | |
| 3377 | There is no runtime checking that a required key is actually provided |
| 3378 | when instantiating a related TypedDict. |
| 3379 | """ |
| 3380 | item = _type_check(parameters, f'{self._name} accepts only a single type.') |
| 3381 | return _GenericAlias(self, (item,)) |
| 3382 | |
| 3383 | |
| 3384 | @_SpecialForm |