这是indexloc提供的服务,不要输入任何密码
Skip to content

RUF012 warns on variable re-assignment within top level of class body #21389

@anabelle2001

Description

@anabelle2001

Summary

The second assignment reports that ROI_COLORS is not annotated with ClassVar. I think this is a false positive.

View in Playground: https://play.ruff.rs/d208fa8c-4554-415c-86cd-9986c0a0d76f

from typing import ClassVar
import matplotlib

class SomeClass:
    ROI_COLORS: ClassVar[list] = matplotlib.color_sequences["tab20"]

    # Shuffle the order around
    ROI_COLORS = [*ROI_COLORS[0::2], *ROI_COLORS[1::2]]  # Mutable class attributes should be annotated with `typing.ClassVar` (RUF012) [Ln 11, Col 18]

Version

ruff 0.14.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions