Skip to content

RUF012 should allow plain ClassVar #6267

@bluetech

Description

@bluetech

Running ruff 0.0.282 using ruff --isolated --select=RUF012 on the following file:

from typing import ClassVar

class C:
    f: ClassVar = {0}

gives

x.py:4:19: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`

I think Ruff should not emit RUF012 for this, since if ClassVar is used without the [...] part, the type checkers infer the type, i.e. the [...] part is optional, similar to Final.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions