---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF009 Do not perform function call `default_function` in dataclass defaults
  --> RUF009.py:20:41
   |
18 | @dataclass()
19 | class A:
20 |     hidden_mutable_default: list[int] = default_function()
   |                                         ^^^^^^^^^^^^^^^^^^
21 |     class_variable: typing.ClassVar[list[int]] = default_function()
22 |     another_class_var: ClassVar[list[int]] = default_function()
   |

RUF009 Do not perform function call `default_function` in dataclass defaults
  --> RUF009.py:43:41
   |
41 | @dataclass
42 | class B:
43 |     hidden_mutable_default: list[int] = default_function()
   |                                         ^^^^^^^^^^^^^^^^^^
44 |     another_dataclass: A = A()
45 |     not_optimal: ImmutableType = ImmutableType(20)
   |

RUF009 Do not perform function call `A` in dataclass defaults
  --> RUF009.py:44:28
   |
42 | class B:
43 |     hidden_mutable_default: list[int] = default_function()
44 |     another_dataclass: A = A()
   |                            ^^^
45 |     not_optimal: ImmutableType = ImmutableType(20)
46 |     good_variant: ImmutableType = DEFAULT_IMMUTABLETYPE_FOR_ALL_DATACLASSES
   |

RUF009 Do not perform function call `ImmutableType` in dataclass defaults
  --> RUF009.py:45:34
   |
43 |     hidden_mutable_default: list[int] = default_function()
44 |     another_dataclass: A = A()
45 |     not_optimal: ImmutableType = ImmutableType(20)
   |                                  ^^^^^^^^^^^^^^^^^
46 |     good_variant: ImmutableType = DEFAULT_IMMUTABLETYPE_FOR_ALL_DATACLASSES
47 |     okay_variant: A = DEFAULT_A_FOR_ALL_DATACLASSES
   |

RUF009 Do not perform function call `ListOfStrings` in dataclass defaults
  --> RUF009.py:91:24
   |
89 | class DataclassWithNewTypeFields:
90 |     # Errors
91 |     a: ListOfStrings = ListOfStrings([])
   |                        ^^^^^^^^^^^^^^^^^
92 |     b: StringsToInts = StringsToInts()
93 |     c: Invalid1 = Invalid1()
   |

RUF009 Do not perform function call `StringsToInts` in dataclass defaults
  --> RUF009.py:92:24
   |
90 |     # Errors
91 |     a: ListOfStrings = ListOfStrings([])
92 |     b: StringsToInts = StringsToInts()
   |                        ^^^^^^^^^^^^^^^
93 |     c: Invalid1 = Invalid1()
94 |     d: Invalid2 = Invalid2()
   |

RUF009 Do not perform function call `Invalid1` in dataclass defaults
  --> RUF009.py:93:19
   |
91 |     a: ListOfStrings = ListOfStrings([])
92 |     b: StringsToInts = StringsToInts()
93 |     c: Invalid1 = Invalid1()
   |                   ^^^^^^^^^^
94 |     d: Invalid2 = Invalid2()
95 |     e: Invalid3 = Invalid3()
   |

RUF009 Do not perform function call `Invalid2` in dataclass defaults
  --> RUF009.py:94:19
   |
92 |     b: StringsToInts = StringsToInts()
93 |     c: Invalid1 = Invalid1()
94 |     d: Invalid2 = Invalid2()
   |                   ^^^^^^^^^^
95 |     e: Invalid3 = Invalid3()
   |

RUF009 Do not perform function call `Invalid3` in dataclass defaults
  --> RUF009.py:95:19
   |
93 |     c: Invalid1 = Invalid1()
94 |     d: Invalid2 = Invalid2()
95 |     e: Invalid3 = Invalid3()
   |                   ^^^^^^^^^^
96 |
97 |     # No errors
   |

RUF009 Do not perform function call `default_function` in dataclass defaults
   --> RUF009.py:109:35
    |
107 | @dataclass
108 | class ShouldMatchB008RuleOfImmutableTypeAnnotationIgnored:
109 |     this_is_not_fine: list[int] = default_function()
    |                                   ^^^^^^^^^^^^^^^^^^
110 |     # ignored
111 |     this_is_fine: int = f()
    |
