---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF033 `__post_init__` method with argument defaults
  --> RUF033.py:19:35
   |
17 |     baz: InitVar[int] = 1
18 |
19 |     def __post_init__(self, bar = 11, baz = 11) -> None: ...
   |                                   ^^
   |
help: Use `dataclasses.InitVar` instead

RUF033 `__post_init__` method with argument defaults
  --> RUF033.py:19:45
   |
17 |     baz: InitVar[int] = 1
18 |
19 |     def __post_init__(self, bar = 11, baz = 11) -> None: ...
   |                                             ^^
   |
help: Use `dataclasses.InitVar` instead

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:25:35
   |
23 | @dataclass
24 | class Foo:
25 |     def __post_init__(self, bar = 11, baz = 11) -> None: ...
   |                                   ^^
   |
help: Use `dataclasses.InitVar` instead
   |
24 | class Foo:
   -     def __post_init__(self, bar = 11, baz = 11) -> None: ...
25 +     bar: InitVar = 11
26 +     def __post_init__(self, bar, baz = 11) -> None: ...
27 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:25:45
   |
23 | @dataclass
24 | class Foo:
25 |     def __post_init__(self, bar = 11, baz = 11) -> None: ...
   |                                             ^^
   |
help: Use `dataclasses.InitVar` instead
   |
24 | class Foo:
   -     def __post_init__(self, bar = 11, baz = 11) -> None: ...
25 +     baz: InitVar = 11
26 +     def __post_init__(self, bar = 11, baz) -> None: ...
27 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:46:40
   |
44 | @dataclass
45 | class Foo:
46 |     def __post_init__(self, bar: int = 11, baz: Something[Whatever | None] = 11) -> None: ...
   |                                        ^^
   |
help: Use `dataclasses.InitVar` instead
   |
45 | class Foo:
   -     def __post_init__(self, bar: int = 11, baz: Something[Whatever | None] = 11) -> None: ...
46 +     bar: InitVar[int] = 11
47 +     def __post_init__(self, bar: int, baz: Something[Whatever | None] = 11) -> None: ...
48 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:46:78
   |
44 | @dataclass
45 | class Foo:
46 |     def __post_init__(self, bar: int = 11, baz: Something[Whatever | None] = 11) -> None: ...
   |                                                                              ^^
   |
help: Use `dataclasses.InitVar` instead
   |
45 | class Foo:
   -     def __post_init__(self, bar: int = 11, baz: Something[Whatever | None] = 11) -> None: ...
46 +     baz: InitVar[Something[Whatever | None]] = 11
47 +     def __post_init__(self, bar: int = 11, baz: Something[Whatever | None]) -> None: ...
48 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:59:40
   |
57 |     ping = "pong"
58 |
59 |     def __post_init__(self, bar: int = 11, baz: int = 12) -> None: ...
   |                                        ^^
   |
help: Use `dataclasses.InitVar` instead
   |
58 |
   -     def __post_init__(self, bar: int = 11, baz: int = 12) -> None: ...
59 +     bar: InitVar[int] = 11
60 +     def __post_init__(self, bar: int, baz: int = 12) -> None: ...
61 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:59:55
   |
57 |     ping = "pong"
58 |
59 |     def __post_init__(self, bar: int = 11, baz: int = 12) -> None: ...
   |                                                       ^^
   |
help: Use `dataclasses.InitVar` instead
   |
58 |
   -     def __post_init__(self, bar: int = 11, baz: int = 12) -> None: ...
59 +     baz: InitVar[int] = 12
60 +     def __post_init__(self, bar: int = 11, baz: int) -> None: ...
61 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 `__post_init__` method with argument defaults
  --> RUF033.py:67:40
   |
65 |     bar = "should've used attrs"
66 |
67 |     def __post_init__(self, bar: str = "ahhh", baz: str = "hmm") -> None: ...
   |                                        ^^^^^^
   |
help: Use `dataclasses.InitVar` instead

RUF033 `__post_init__` method with argument defaults
  --> RUF033.py:67:59
   |
65 |     bar = "should've used attrs"
66 |
67 |     def __post_init__(self, bar: str = "ahhh", baz: str = "hmm") -> None: ...
   |                                                           ^^^^^
   |
help: Use `dataclasses.InitVar` instead

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:73:41
   |
71 | @dataclass
72 | class Foo:
73 |     def __post_init__(self, bar: int = (x := 1)) -> None:
   |                                         ^^^^^^
74 |         pass
   |
help: Use `dataclasses.InitVar` instead
   |
72 | class Foo:
   -     def __post_init__(self, bar: int = (x := 1)) -> None:
73 +     bar: InitVar[int] = (x := 1)
74 +     def __post_init__(self, bar: int) -> None:
75 |         pass
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:81:21
   |
79 |     def __post_init__(
80 |         self,
81 |         bar: int = (x := 1)  #  comment
   |                     ^^^^^^
82 |         ,
83 |         baz: int = (y := 2),  # comment
   |
help: Use `dataclasses.InitVar` instead
   |
78 | class Foo:
79 +     bar: InitVar[int] = (x := 1)
80 |     def __post_init__(
81 |         self,
   -         bar: int = (x := 1)  #  comment
82 +         bar: int  #  comment
83 |         ,
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:83:21
   |
81 |         bar: int = (x := 1)  #  comment
82 |         ,
83 |         baz: int = (y := 2),  # comment
   |                     ^^^^^^
84 |         foo = (a := 1)  #  comment
85 |         ,
   |
help: Use `dataclasses.InitVar` instead
   |
78 | class Foo:
79 +     baz: InitVar[int] = (y := 2)
80 |     def __post_init__(
81 |         self,
82 |         bar: int = (x := 1)  #  comment
83 |         ,
   -         baz: int = (y := 2),  # comment
84 +         baz: int,  # comment
85 |         foo = (a := 1)  #  comment
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:84:16
   |
82 |         ,
83 |         baz: int = (y := 2),  # comment
84 |         foo = (a := 1)  #  comment
   |                ^^^^^^
85 |         ,
86 |         faz = (b := 2),  # comment
   |
help: Use `dataclasses.InitVar` instead
   |
78 | class Foo:
79 +     foo: InitVar = (a := 1)
80 |     def __post_init__(
--------------------------------------------------------------------------------
84 |         baz: int = (y := 2),  # comment
   -         foo = (a := 1)  #  comment
85 +         foo  #  comment
86 |         ,
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:86:16
   |
84 |         foo = (a := 1)  #  comment
85 |         ,
86 |         faz = (b := 2),  # comment
   |                ^^^^^^
87 |     ) -> None:
88 |         pass
   |
help: Use `dataclasses.InitVar` instead
   |
78 | class Foo:
79 +     faz: InitVar = (b := 2)
80 |     def __post_init__(
--------------------------------------------------------------------------------
86 |         ,
   -         faz = (b := 2),  # comment
87 +         faz,  # comment
88 |     ) -> None:
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:95:20
   |
93 |     def __post_init__(
94 |         self,
95 |         bar: int = 1,  # comment
   |                    ^
96 |         baz: int = 2,  # comment
97 |     ) -> None:
   |
help: Use `dataclasses.InitVar` instead
   |
92 | class Foo:
93 +     bar: InitVar[int] = 1
94 |     def __post_init__(
95 |         self,
   -         bar: int = 1,  # comment
96 +         bar: int,  # comment
97 |         baz: int = 2,  # comment
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
  --> RUF033.py:96:20
   |
94 |         self,
95 |         bar: int = 1,  # comment
96 |         baz: int = 2,  # comment
   |                    ^
97 |     ) -> None:
98 |         pass
   |
help: Use `dataclasses.InitVar` instead
   |
92 | class Foo:
93 +     baz: InitVar[int] = 2
94 |     def __post_init__(
95 |         self,
96 |         bar: int = 1,  # comment
   -         baz: int = 2,  # comment
97 +         baz: int,  # comment
98 |     ) -> None:
   |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:105:22
    |
103 |     def __post_init__(
104 |         self,
105 |         arg1: int = (1)  # comment
    |                      ^
106 |         ,
107 |         arg2: int = ((1))  # comment
    |
help: Use `dataclasses.InitVar` instead
    |
102 | class Foo:
103 +     arg1: InitVar[int] = (1)
104 |     def __post_init__(
105 |         self,
    -         arg1: int = (1)  # comment
106 +         arg1: int  # comment
107 |         ,
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:107:23
    |
105 |         arg1: int = (1)  # comment
106 |         ,
107 |         arg2: int = ((1))  # comment
    |                       ^
108 |         ,
109 |         arg2: int = (i for i in range(10))  # comment
    |
help: Use `dataclasses.InitVar` instead
    |
102 | class Foo:
103 +     arg2: InitVar[int] = ((1))
104 |     def __post_init__(
105 |         self,
106 |         arg1: int = (1)  # comment
107 |         ,
    -         arg2: int = ((1))  # comment
108 +         arg2: int  # comment
109 |         ,
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:109:21
    |
107 |         arg2: int = ((1))  # comment
108 |         ,
109 |         arg2: int = (i for i in range(10))  # comment
    |                     ^^^^^^^^^^^^^^^^^^^^^^
110 |         ,
111 |     ) -> None:
    |
help: Use `dataclasses.InitVar` instead
    |
102 | class Foo:
103 +     arg2: InitVar[int] = (i for i in range(10))
104 |     def __post_init__(
--------------------------------------------------------------------------------
109 |         ,
    -         arg2: int = (i for i in range(10))  # comment
110 +         arg2: int  # comment
111 |         ,
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:121:27
    |
119 |         def __post_init__(
120 |             self,
121 |             bar: (int) = (yield from range(5))  # comment
    |                           ^^^^^^^^^^^^^^^^^^^
122 |             ,
123 |         ) -> None:
    |
help: Use `dataclasses.InitVar` instead
    |
118 |     class Foo:
119 +         bar: InitVar[int] = (yield from range(5))
120 |         def __post_init__(
121 |             self,
    -             bar: (int) = (yield from range(5))  # comment
122 +             bar: (int)  # comment
123 |             ,
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:131:50
    |
129 |   @dataclass
130 |   class C:
131 |       def __post_init__(self, x: tuple[int, ...] = (
    |  __________________________________________________^
132 | |         1,
133 | |         2,
134 | |     )) -> None:
    | |_____^
135 |           self.x = x
    |
help: Use `dataclasses.InitVar` instead
    |
130 | class C:
    -     def __post_init__(self, x: tuple[int, ...] = (
131 +     x: InitVar[tuple[int, ...]] = (
132 |         1,
133 |         2,
    -     )) -> None:
134 +     )
135 +     def __post_init__(self, x: tuple[int, ...]) -> None:
136 |         self.x = x
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 [*] `__post_init__` method with argument defaults
   --> RUF033.py:140:38
    |
138 |   @dataclass
139 |   class D:
140 |       def __post_init__(self, x: int = """
    |  ______________________________________^
141 | |     """) -> None:
    | |_______^
142 |           self.x = x
    |
help: Use `dataclasses.InitVar` instead
    |
139 | class D:
    -     def __post_init__(self, x: int = """
    -     """) -> None:
140 +     x: InitVar[int] = """
141 +     """
142 +     def __post_init__(self, x: int) -> None:
143 |         self.x = x
    |
note: This is an unsafe fix and may change runtime behavior

RUF033 `__post_init__` method with argument defaults
   --> RUF033.py:149:60
    |
147 | @dataclass
148 | class E:
149 |     def __post_init__[T: (str, bytes)](self, a: T | None = None, b: T | None = None) -> None:
    |                                                            ^^^^
150 |         self.a = str(a)
151 |         self.b = str(b)
    |
help: Use `dataclasses.InitVar` instead

RUF033 `__post_init__` method with argument defaults
   --> RUF033.py:149:80
    |
147 | @dataclass
148 | class E:
149 |     def __post_init__[T: (str, bytes)](self, a: T | None = None, b: T | None = None) -> None:
    |                                                                                ^^^^
150 |         self.a = str(a)
151 |         self.b = str(b)
    |
help: Use `dataclasses.InitVar` instead
