MCPcopy Index your code
hub / github.com/python/cpython / Required

Function Required

Lib/typing.py:3412–3432  ·  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

3410
3411@_SpecialForm
3412def 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

Callers 1

test_cannot_initMethod · 0.90

Calls 2

_type_checkFunction · 0.85
_GenericAliasClass · 0.85

Tested by 1

test_cannot_initMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…