Skip to content

RUF012 false positive with annotations set as strings #12288

@ZeeD

Description

@ZeeD

minimal case:

from typing import ClassVar
from typing import Final


class C:
    cv_orig: ClassVar[list[int]] = []
    cv_str: 'ClassVar[list[int]]' = []

    cv_final_orig: Final[list[int]] = []
    cv_final_str: 'Final[list[int]]' = []

    use_case: 'Final[list[C]]' = []

with ruff 0.5.1 I got the error

RUF012 Mutable class attributes should be annotated with `typing.ClassVar`

for cv_str, cv_final_str and use_case (that was my initial scenario...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions