Skip to content

ClassVar cannot be overridden with Final #20183

@romintomasetti

Description

@romintomasetti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-finalPEP 591

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions