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

Function ReadOnly

Lib/typing.py:3404–3420  ·  view source on GitHub ↗

A special typing construct to mark an item of a TypedDict as read-only. For example:: class Movie(TypedDict): title: ReadOnly[str] year: int def mutate_movie(m: Movie) -> None: m["year"] = 1992 # allowed m["title"] = "The Matrix

(self, parameters)

Source from the content-addressed store, hash-verified

3402
3403@_SpecialForm
3404def ReadOnly(self, parameters):
3405 """A special typing construct to mark an item of a TypedDict as read-only.
3406
3407 For example::
3408
3409 class Movie(TypedDict):
3410 title: ReadOnly[str]
3411 year: int
3412
3413 def mutate_movie(m: Movie) -> None:
3414 m["year"] = 1992 # allowed
3415 m["title"] = "The Matrix" # typechecker error
3416
3417 There is no runtime checking for this property.
3418 """
3419 item = _type_check(parameters, f'{self._name} accepts only a single type.')
3420 return _GenericAlias(self, (item,))
3421
3422
3423class NewType:

Callers

nothing calls this directly

Calls 2

_type_checkFunction · 0.85
_GenericAliasClass · 0.85

Tested by

no test coverage detected