MCPcopy Index your code
hub / github.com/RustPython/RustPython / Required

Function Required

Lib/typing.py:3361–3381  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

3359
3360@_SpecialForm
3361def 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

Callers 1

test_cannot_initMethod · 0.90

Calls 2

_type_checkFunction · 0.85
_GenericAliasClass · 0.85

Tested by 1

test_cannot_initMethod · 0.72