Skip to content

RUF008 false positive on class variable #5043

@hauntsaninja

Description

@hauntsaninja
λ cat xyz.py
from dataclasses import dataclass

@dataclass
class X:
    class_var = {}
    x: int

print(X(123).x)

λ ruff check xyz.py --select RUF008
xyz.py:5:17: RUF008 Do not use mutable default values for dataclass attributes
Found 1 error.

This is a false positive, class_var is not a dataclass attribute. Python 3.11 (which tries to error at runtime for mutable dataclass attributes) also accepts it

Metadata

Metadata

Assignees

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