`ClassVar` cannot be overridden with `Final`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
A typing.ClassVar cannot be overridden with typing.Final.
main.py:7: error: Cannot override class variable (previously declared on base class "Base") with instance variable [misc]
Found 1 error in 1 file (checked 1 source file)
To Reproduce
import typing
class Base:
value : typing.ClassVar[str]
class Derived(Base):
value : typing.Final[str] = 'derived'
https://mypy-play.net/?mypy=latest&python=3.12&flags=verbose&gist=03819c6e8c7b6fb53baebe094faed123
Expected Behavior
I though using a typing.Final annotation would imply typing.ClassVar.
Actual Behavior
It seems not allowed to override a ClassVar with a Final.
Your Environment
See reproducer.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Python reproducer and trace how mypy handles overriding a ClassVar with a Final annotation. Confirm the intended typing behavior and add coverage for this case; done means the reproducer no longer reports the incorrect override error and existing checks remain passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100