@@ -10,11 +10,35 @@ Class type assignability
1010
1111(Originally specified in :pep: `526 `.)
1212
13- A :term: `type qualifier ` ``ClassVar[T] `` exists in the :py:mod: `typing `
14- module. It accepts only a single argument that should be a valid type,
15- and is used to annotate class variables that should not be set on class
16- instances. This restriction is enforced by static checkers,
17- but not at runtime.
13+ The :py:data: `typing.ClassVar ` :term: `type qualifier ` is used to annotate
14+ class variables that should not be set on class instances. This restriction
15+ is enforced by static checkers, but not at runtime.
16+
17+ Syntax
18+ ^^^^^^
19+
20+ :py:data: `~typing.ClassVar ` may be used in one of several forms:
21+
22+ * With an explicit type, using the syntax ``ClassVar[<type>] ``. Example::
23+
24+ class C:
25+ x: ClassVar[float] = 1
26+
27+ * With no type annotation. Example::
28+
29+ class C:
30+ y: ClassVar = 2
31+ z: ClassVar
32+
33+ If an assigned value is available (e.g. with ``y``), the type should be
34+ inferred as some type to which this value is :term:`assignable` (in this
35+ case, either ``int``, ``Literal[2]``, or ``Any``).
36+
37+ If the ``ClassVar`` qualifier is used without any assigned value, the type
38+ should be inferred to an unknown static type (such as :ref:`Any`).
39+
40+ Semantics and examples
41+ ^^^^^^^^^^^^^^^^^^^^^^
1842
1943Type annotations can be used to annotate class and instance variables
2044in class bodies and methods. In particular, the value-less notation ``a: int ``
0 commit comments