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)
| 3402 | |
| 3403 | @_SpecialForm |
| 3404 | def 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 | |
| 3423 | class NewType: |
nothing calls this directly
no test coverage detected