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)
| 3453 | |
| 3454 | @_SpecialForm |
| 3455 | def 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 | |
| 3474 | class NewType: |
nothing calls this directly
no test coverage detected
searching dependent graphs…