Skip to content

ClassVar[Final[T]] should be allowed #10500

@ben-alexander

Description

@ben-alexander

Pyright doesn't allow the construction Final[ClassVar[T]], typing.ClassVar states:

Changed in version 3.13: ClassVar can now be nested in Final and vice versa.

from typing import ClassVar, Final

class A:
    var: ClassVar[str] = 'a'

class B(A):
    var: Final[ClassVar[str]] = 'b'

# "ClassVar" is not allowed in this context Pylance(reportInvalidTypeForm)

There was a previous report #7959 specific to dataclasses from before the release of 3.13. I'm not sure where this restriction to dataclasses comes from as the typing spec doesn't mention this in 3.12.

Running Pylance in VS Code. Version: 2025.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions