-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
From #14327:
Note that
RUF009can be a bit misleading whenauto_attribs=False(or with olderattr.scodebases):import attrs @attrs.define(auto_attribs=False) class X: a_field: int = attrs.field(default=42) not_a_field: list = (lambda: [])() # ^^^^^^^^^^^^^^ RUF009 Do not perform function call in dataclass defaultsWithout
auto_attribs,not_a_fieldcan't possibly be adataclassfield. In this example, it's an incorrectly typed class variable. Fixing the typing error also fixes theRUF009warning:@attrs.define(auto_attribs=False) class X: a_field: int = attrs.field(default=42) not_a_field: typing.ClassVar[list] = (lambda: [])()This is an issue though when using
attrs.fieldwrappers:def my_field(): return attrs.field(default=42, metadata={"my_metadata": 42}) @attrs.define(auto_attribs=False) class X: a_field: int = my_field() # ^^^^^^^^^^ RUF009 Do not perform function call `my_field` in dataclass defaults— @pwuertz
Metadata
Metadata
Assignees
Labels
No labels