@@ -183,7 +183,7 @@ expression, and it represents the type described by that type expression.
183
183
184
184
``TypeForm `` is a special form that, when used in a type expression, describes
185
185
a set of type form objects. It accepts a single type argument, which must be a
186
- valid type expression. ``TypeForm[T] `` describes the set of all type form
186
+ :ref: ` valid type expression < valid-type-expressions >` . ``TypeForm[T] `` describes the set of all type form
187
187
objects that represent the type ``T `` or types that are
188
188
:term: `assignable to <typing:assignable> ` ``T ``. For example,
189
189
``TypeForm[str | None] `` describes the set of all type form objects
@@ -218,9 +218,7 @@ equivalent to ``TypeForm[Any]``.
218
218
Implicit ``TypeForm `` Evaluation
219
219
--------------------------------
220
220
221
- When a static type checker encounters an expression that follows all of the
222
- syntactic, semantic and contextual rules for a type expression as detailed
223
- in the typing spec, the evaluated type of this expression should be assignable
221
+ When a static type checker encounters a valid type expression, the evaluated type of this expression should be assignable
224
222
to ``TypeForm[T] `` if the type it describes is assignable to ``T ``.
225
223
226
224
For example, if a static type checker encounters the expression ``str | None ``,
@@ -248,6 +246,11 @@ be assignable to ``TypeForm``::
248
246
249
247
v5: TypeForm[set[str]] = "set[str]" # OK
250
248
249
+ .. _valid-type-expressions :
250
+
251
+ Valid Type Expressions
252
+ ----------------------
253
+
251
254
The typing spec defines syntactic rules for type expressions in the form of a
252
255
:ref: `formal grammar <typing:expression-grammar >`. Semantic rules are specified
253
256
as comments along with the grammar definition. Contextual requirements are detailed
@@ -256,8 +259,11 @@ type expressions. For example, the special form ``Self`` can be used in a
256
259
type expression only within a class, and a type variable can be used within
257
260
a type expression only when it is associated with a valid scope.
258
261
259
- Expressions that violate one or more of the syntactic, semantic, or contextual
260
- rules for type expressions should not evaluate to a ``TypeForm `` type.::
262
+ A valid type expression is an expression that follows all of the syntactic,
263
+ semantic, and contextual rules for a type expression.
264
+
265
+ Expressions that are not valid type expressions should not evaluate to a
266
+ ``TypeForm `` type::
261
267
262
268
bad1: TypeForm = tuple() # Error: Call expression not allowed in type expression
263
269
bad2: TypeForm = (1, 2) # Error: Tuple expression not allowed in type expression
0 commit comments