Skip to content

ruff-mutable-default (RUF008) not not catching mutable default passed to attrs.field. #16495

@ashb

Description

@ashb

Simple repro case

❯ cat tst.py
import attrs

@attrs.define
class B :
    mutable_default: list[int] = []
    mutable_default2: list[int] = attrs.field(default=[])

❯ uvx ruff@0.9.9 check --extend-select RUF008,B006 --preview -n --isolated  tst.py
All checks passed!

Originally posted by @ashb in #14327 (comment)

Output:

tst.py:5:34: RUF008 Do not use mutable default values for dataclass attributes
  |
3 | @attrs.define
4 | class B :
5 |     mutable_default: list[int] = []
  |                                  ^^ RUF008
6 |     mutable_default2: list[int] = attrs.field(default=[])
  |

I was hoping it would catch the same error on mutable_default2

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcomeruleImplementing 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