Missing warning when using ClassVar without subscript
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
Please see code below. When bare ClassVar is used, instance assignment is not warned.
As far as I understand the [specs](https://typing.python.org/en/latest/spec/class-compat.html#classvar), using ClassVar without a subscript type only changes how its type is inferred, but not its behavior as a class variable.
**Code or Screenshots**
Code sample in [pyright playground](https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoDCANgIYDOZAaiSALABQDDAxqRVAELkCmAXA1EFRgYML0JsqNANqoYAXSgBeKAAYBQgEY1xxclJDK1TRvVb6oAZQCumgBRcy3AJT96QqABNuwKAH0-VCQYALsnImBnKABaAD4oADkwFD4ND0Fw4AA6ETAjVUEAYigQbhw8AEEYGBAkTWsYbgrmZm4KAEkKa24ocihuAA8EbmZGzzT0zKztQxUCqGKyAAswayJPKCWSADcemCWeshIIHqQunvr8FDB8AHcaFPH6IA)
```python
from typing import ClassVar
class Base:
foo: ClassVar[int] = 0
bar: ClassVar = 0
class Sub(Base):
def __init__(self) -> None:
self.foo = 0 # reportAttributeAccessIssue as expected
self.bar = 0 # should have the same issue but not warned
```
**VS Code extension or command-line**
VSCode with Pylance 2025.10.4, as well as pyright playground with 1.1.407
Contributor guide
Research direction
Reproduce the issue with the provided Python sample in the Pyright playground or command line, comparing bare ClassVar with ClassVar[int]. Trace the diagnostic handling for instance assignment to ClassVar; done means assigning to either declaration produces the expected attribute-access warning without regressing typed ClassVar behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100