Skip to content

Commit 0e355b7

Browse files
committed
Feedback, add conformance test
1 parent d2d8036 commit 0e355b7

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

conformance/tests/classes_classvar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class ClassA(Generic[T, P]):
5858
good2: ClassVar[list[str]] = []
5959
good3: ClassVar[Any] = 1
6060
good4: ClassVar = 3.1
61-
good5: Annotated[ClassVar[list[int]], ""] = []
61+
good5: ClassVar
62+
good6: Annotated[ClassVar[list[int]], ""] = []
6263

6364
def method1(self, a: ClassVar[int]): # E: ClassVar not allowed here
6465
x: ClassVar[str] = "" # E: ClassVar not allowed here
@@ -76,6 +77,7 @@ def method2(self) -> ClassVar[int]: # E: ClassVar not allowed here
7677
assert_type(ClassA.good2, list[str])
7778
assert_type(ClassA.good3, Any)
7879
assert_type(ClassA.good4, float)
80+
assert_type(ClassA.good5, Any)
7981

8082

8183
class BasicStarship:

docs/spec/class-compat.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ The :py:data:`typing.ClassVar` :term:`type qualifier` is used to annotate
1414
class variables that should not be set on class instances. This restriction
1515
is enforced by static checkers, but not at runtime.
1616

17-
Syntax
18-
^^^^^^
19-
2017
:py:data:`~typing.ClassVar` may be used in one of several forms:
2118

2219
* With an explicit type, using the syntax ``ClassVar[<type>]``. Example::
@@ -31,14 +28,11 @@ Syntax
3128
z: ClassVar
3229

3330
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``).
31+
inferred as some type to which this value is :term:`assignable` (for example,
32+
``int``, ``Literal[2]``, or ``Any``).
3633

3734
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-
^^^^^^^^^^^^^^^^^^^^^^
35+
should be inferred as :ref:`any`.
4236

4337
Type annotations can be used to annotate class and instance variables
4438
in class bodies and methods. In particular, the value-less notation ``a: int``

0 commit comments

Comments
 (0)