-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUF009 should behave similar to B008 and ignore attributes with immut…
…able types (#16048) This PR resolved #15772 Before PR: ``` def _( this_is_fine: int = f(), # No error this_is_not: list[int] = f() # B008: Do not perform function call `f` in argument defaults ): ... @DataClass class _: this_is_not_fine: list[int] = f() # RUF009: Do not perform function call `f` in dataclass defaults this_is_also_not: int = f() # RUF009: Do not perform function call `f` in dataclass defaults ``` After PR: ``` def _( this_is_fine: int = f(), # No error this_is_not: list[int] = f() # B008: Do not perform function call `f` in argument defaults ): ... @DataClass class _: this_is_not_fine: list[int] = f() # RUF009: Do not perform function call `f` in dataclass defaults this_is_fine: int = f() ```
- Loading branch information
1 parent
07cf885
commit d2f661f
Showing
4 changed files
with
29 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 1 addition & 106 deletions
107
.../ruff/snapshots/ruff_linter__rules__ruff__tests__RUF009_RUF009_attrs_auto_attribs.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,5 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/ruff/mod.rs | ||
snapshot_kind: text | ||
--- | ||
RUF009_attrs_auto_attribs.py:12:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
10 | a: str = 0 | ||
11 | b = field() | ||
12 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
13 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:20:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
18 | a: str = 0 | ||
19 | b = field() | ||
20 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
21 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:28:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
26 | a: str = 0 | ||
27 | b = field() | ||
28 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
29 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:36:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
34 | a: str = 0 | ||
35 | b = field() | ||
36 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
37 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:44:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
42 | a: str = 0 | ||
43 | b = field() | ||
44 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
45 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:52:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
50 | a: str = 0 | ||
51 | b = field() | ||
52 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
53 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:60:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
58 | a: str = 0 | ||
59 | b = field() | ||
60 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
61 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:68:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
66 | a: str = 0 | ||
67 | b = field() | ||
68 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
69 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:76:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
74 | a: str = 0 | ||
75 | b = field() | ||
76 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
77 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:92:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
90 | a: str = 0 | ||
91 | b = field() | ||
92 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
93 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:100:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
98 | a: str = 0 | ||
99 | b = field() | ||
100 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
101 | d = list() | ||
| | ||
|
||
RUF009_attrs_auto_attribs.py:116:14: RUF009 Do not perform function call `foo` in dataclass defaults | ||
| | ||
114 | a: str = 0 | ||
115 | b = field() | ||
116 | c: int = foo() | ||
| ^^^^^ RUF009 | ||
117 | d = list() | ||
| |