-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
astral-sh/ruff
#23184Labels
bugSomething isn't workingSomething isn't workinggenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementationtyping semanticstyping-module features, spec compliance, etctyping-module features, spec compliance, etc
Milestone
Description
Summary
Note that a ClassVar parameter cannot include any type variables, regardless of the level of nesting: ClassVar[T] and ClassVar[list[set[T]]] are both invalid if T is a type variable.
I find their example unnecessarily complicated, here's a simpler reproducer
from typing import ClassVar, reveal_type, cast
class Box[T]:
value: ClassVar[T] = cast(T, None)
int_box = Box[int]()
reveal_type(int_box.value)
str_box = Box[str]()
reveal_type(str_box.value)
Currently this passes, inferring conflicting types:
info[revealed-type]: Revealed type
--> test_classvar.py:7:13
|
6 | int_box = Box[int]()
7 | reveal_type(int_box.value)
| ^^^^^^^^^^^^^ `int`
8 |
9 | str_box = Box[str]()
|
info[revealed-type]: Revealed type
--> test_classvar.py:10:13
|
9 | str_box = Box[str]()
10 | reveal_type(str_box.value)
| ^^^^^^^^^^^^^ `str`
|
Found 2 diagnostics
Expected result
Should be rejected, e.g. mypy rejects this with error: ClassVar cannot contain type variables [misc]
Relevant issues
- perhaps somewhat relevant to Tracking issue for override-related checks (including the Liskov Substitution Principle) #166
Version
ty 0.0.1-alpha.7
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggenericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementationtyping semanticstyping-module features, spec compliance, etctyping-module features, spec compliance, etc