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

Function ReadOnly

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

3453
3454@_SpecialForm
3455def ReadOnly(self, parameters):
3456 """A special typing construct to mark an item of a TypedDict as read-only.
3457
3458 For example::
3459
3460 class Movie(TypedDict):
3461 title: ReadOnly[str]
3462 year: int
3463
3464 def mutate_movie(m: Movie) -> None:
3465 m["year"] = 1992 # allowed
3466 m["title"] = "The Matrix" # typechecker error
3467
3468 There is no runtime checking for this property.
3469 """
3470 item = _type_check(parameters, f'{self._name} accepts only a single type.')
3471 return _GenericAlias(self, (item,))
3472
3473
3474class NewType:

Callers

nothing calls this directly

Calls 2

_type_checkFunction · 0.85
_GenericAliasClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…