-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parenthesize expressins when converting to B009 (#7091)
- Loading branch information
1 parent
37d244d
commit 9c3b2c3
Showing
4 changed files
with
161 additions
and
92 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
148 changes: 74 additions & 74 deletions
148
...rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B010_B009_B010.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,120 +1,120 @@ | ||
--- | ||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs | ||
--- | ||
B009_B010.py:46:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:50:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
45 | # Invalid usage | ||
46 | setattr(foo, "bar", None) | ||
49 | # Invalid usage | ||
50 | setattr(foo, "bar", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
47 | setattr(foo, "_123abc", None) | ||
48 | setattr(foo, "__123abc__", None) | ||
51 | setattr(foo, "_123abc", None) | ||
52 | setattr(foo, "__123abc__", None) | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
43 43 | pass | ||
44 44 | | ||
45 45 | # Invalid usage | ||
46 |-setattr(foo, "bar", None) | ||
46 |+foo.bar = None | ||
47 47 | setattr(foo, "_123abc", None) | ||
48 48 | setattr(foo, "__123abc__", None) | ||
49 49 | setattr(foo, "abc123", None) | ||
47 47 | pass | ||
48 48 | | ||
49 49 | # Invalid usage | ||
50 |-setattr(foo, "bar", None) | ||
50 |+foo.bar = None | ||
51 51 | setattr(foo, "_123abc", None) | ||
52 52 | setattr(foo, "__123abc__", None) | ||
53 53 | setattr(foo, "abc123", None) | ||
|
||
B009_B010.py:47:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:51:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
45 | # Invalid usage | ||
46 | setattr(foo, "bar", None) | ||
47 | setattr(foo, "_123abc", None) | ||
49 | # Invalid usage | ||
50 | setattr(foo, "bar", None) | ||
51 | setattr(foo, "_123abc", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
48 | setattr(foo, "__123abc__", None) | ||
49 | setattr(foo, "abc123", None) | ||
52 | setattr(foo, "__123abc__", None) | ||
53 | setattr(foo, "abc123", None) | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
44 44 | | ||
45 45 | # Invalid usage | ||
46 46 | setattr(foo, "bar", None) | ||
47 |-setattr(foo, "_123abc", None) | ||
47 |+foo._123abc = None | ||
48 48 | setattr(foo, "__123abc__", None) | ||
49 49 | setattr(foo, "abc123", None) | ||
50 50 | setattr(foo, r"abc123", None) | ||
48 48 | | ||
49 49 | # Invalid usage | ||
50 50 | setattr(foo, "bar", None) | ||
51 |-setattr(foo, "_123abc", None) | ||
51 |+foo._123abc = None | ||
52 52 | setattr(foo, "__123abc__", None) | ||
53 53 | setattr(foo, "abc123", None) | ||
54 54 | setattr(foo, r"abc123", None) | ||
|
||
B009_B010.py:48:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:52:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
46 | setattr(foo, "bar", None) | ||
47 | setattr(foo, "_123abc", None) | ||
48 | setattr(foo, "__123abc__", None) | ||
50 | setattr(foo, "bar", None) | ||
51 | setattr(foo, "_123abc", None) | ||
52 | setattr(foo, "__123abc__", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
49 | setattr(foo, "abc123", None) | ||
50 | setattr(foo, r"abc123", None) | ||
53 | setattr(foo, "abc123", None) | ||
54 | setattr(foo, r"abc123", None) | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
45 45 | # Invalid usage | ||
46 46 | setattr(foo, "bar", None) | ||
47 47 | setattr(foo, "_123abc", None) | ||
48 |-setattr(foo, "__123abc__", None) | ||
48 |+foo.__123abc__ = None | ||
49 49 | setattr(foo, "abc123", None) | ||
50 50 | setattr(foo, r"abc123", None) | ||
51 51 | setattr(foo.bar, r"baz", None) | ||
49 49 | # Invalid usage | ||
50 50 | setattr(foo, "bar", None) | ||
51 51 | setattr(foo, "_123abc", None) | ||
52 |-setattr(foo, "__123abc__", None) | ||
52 |+foo.__123abc__ = None | ||
53 53 | setattr(foo, "abc123", None) | ||
54 54 | setattr(foo, r"abc123", None) | ||
55 55 | setattr(foo.bar, r"baz", None) | ||
|
||
B009_B010.py:49:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:53:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
47 | setattr(foo, "_123abc", None) | ||
48 | setattr(foo, "__123abc__", None) | ||
49 | setattr(foo, "abc123", None) | ||
51 | setattr(foo, "_123abc", None) | ||
52 | setattr(foo, "__123abc__", None) | ||
53 | setattr(foo, "abc123", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
50 | setattr(foo, r"abc123", None) | ||
51 | setattr(foo.bar, r"baz", None) | ||
54 | setattr(foo, r"abc123", None) | ||
55 | setattr(foo.bar, r"baz", None) | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
46 46 | setattr(foo, "bar", None) | ||
47 47 | setattr(foo, "_123abc", None) | ||
48 48 | setattr(foo, "__123abc__", None) | ||
49 |-setattr(foo, "abc123", None) | ||
49 |+foo.abc123 = None | ||
50 50 | setattr(foo, r"abc123", None) | ||
51 51 | setattr(foo.bar, r"baz", None) | ||
50 50 | setattr(foo, "bar", None) | ||
51 51 | setattr(foo, "_123abc", None) | ||
52 52 | setattr(foo, "__123abc__", None) | ||
53 |-setattr(foo, "abc123", None) | ||
53 |+foo.abc123 = None | ||
54 54 | setattr(foo, r"abc123", None) | ||
55 55 | setattr(foo.bar, r"baz", None) | ||
|
||
B009_B010.py:50:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:54:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
48 | setattr(foo, "__123abc__", None) | ||
49 | setattr(foo, "abc123", None) | ||
50 | setattr(foo, r"abc123", None) | ||
52 | setattr(foo, "__123abc__", None) | ||
53 | setattr(foo, "abc123", None) | ||
54 | setattr(foo, r"abc123", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
51 | setattr(foo.bar, r"baz", None) | ||
55 | setattr(foo.bar, r"baz", None) | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
47 47 | setattr(foo, "_123abc", None) | ||
48 48 | setattr(foo, "__123abc__", None) | ||
49 49 | setattr(foo, "abc123", None) | ||
50 |-setattr(foo, r"abc123", None) | ||
50 |+foo.abc123 = None | ||
51 51 | setattr(foo.bar, r"baz", None) | ||
51 51 | setattr(foo, "_123abc", None) | ||
52 52 | setattr(foo, "__123abc__", None) | ||
53 53 | setattr(foo, "abc123", None) | ||
54 |-setattr(foo, r"abc123", None) | ||
54 |+foo.abc123 = None | ||
55 55 | setattr(foo.bar, r"baz", None) | ||
|
||
B009_B010.py:51:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
B009_B010.py:55:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. | ||
| | ||
49 | setattr(foo, "abc123", None) | ||
50 | setattr(foo, r"abc123", None) | ||
51 | setattr(foo.bar, r"baz", None) | ||
53 | setattr(foo, "abc123", None) | ||
54 | setattr(foo, r"abc123", None) | ||
55 | setattr(foo.bar, r"baz", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 | ||
| | ||
= help: Replace `setattr` with assignment | ||
|
||
ℹ Suggested fix | ||
48 48 | setattr(foo, "__123abc__", None) | ||
49 49 | setattr(foo, "abc123", None) | ||
50 50 | setattr(foo, r"abc123", None) | ||
51 |-setattr(foo.bar, r"baz", None) | ||
51 |+foo.bar.baz = None | ||
52 52 | setattr(foo, "__123abc__", None) | ||
53 53 | setattr(foo, "abc123", None) | ||
54 54 | setattr(foo, r"abc123", None) | ||
55 |-setattr(foo.bar, r"baz", None) | ||
55 |+foo.bar.baz = None | ||
|
||
|