A special form representing the value that results from the evaluation of a type expression. This value encodes the information supplied in the type expression, and it represents the type described by that type expression. When used in a type expression, TypeForm describes a set of
(self, parameters)
| 905 | |
| 906 | @_TypeFormForm |
| 907 | def TypeForm(self, parameters): |
| 908 | """A special form representing the value that results from the evaluation |
| 909 | of a type expression. |
| 910 | |
| 911 | This value encodes the information supplied in the type expression, and it |
| 912 | represents the type described by that type expression. |
| 913 | |
| 914 | When used in a type expression, TypeForm describes a set of type form |
| 915 | objects. It accepts a single type argument, which must be a valid type |
| 916 | expression. ``TypeForm[T]`` describes the set of all type form objects that |
| 917 | represent the type T or types that are assignable to T. |
| 918 | |
| 919 | Usage:: |
| 920 | |
| 921 | def cast[T](typ: TypeForm[T], value: Any) -> T: ... |
| 922 | |
| 923 | reveal_type(cast(int, "x")) # int |
| 924 | |
| 925 | See PEP 747 for more information. |
| 926 | """ |
| 927 | item = _type_check(parameters, f'{self} accepts only single type.') |
| 928 | return _GenericAlias(self, (item,)) |
| 929 | |
| 930 | |
| 931 | @_SpecialForm |