-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support variable keys in static dictionary key rule (#9411)
Closes #9410.
- Loading branch information
1 parent
c2c9997
commit 701697c
Showing
5 changed files
with
114 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
data = ["some", "Data"] | ||
constant = 5 | ||
|
||
# Ok | ||
# OK | ||
{value: value.upper() for value in data} | ||
{value.lower(): value.upper() for value in data} | ||
{v: v*v for v in range(10)} | ||
{(0, "a", v): v*v for v in range(10)} # Tuple with variable | ||
{v: v * v for v in range(10)} | ||
{(0, "a", v): v * v for v in range(10)} # Tuple with variable | ||
{constant: value.upper() for value in data for constant in data} | ||
|
||
# Errors | ||
{"key": value.upper() for value in data} | ||
{True: value.upper() for value in data} | ||
{0: value.upper() for value in data} | ||
{(1, "a"): value.upper() for value in data} # constant tuple | ||
{(1, "a"): value.upper() for value in data} # Constant tuple | ||
{constant: value.upper() for value in data} | ||
{constant + constant: value.upper() for value in data} |
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
60 changes: 40 additions & 20 deletions
60
...ff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF011_RUF011.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,40 +1,60 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/ruff/mod.rs | ||
--- | ||
RUF011.py:10:2: RUF011 Dictionary comprehension uses static key: `"key"` | ||
RUF011.py:12:2: RUF011 Dictionary comprehension uses static key: `"key"` | ||
| | ||
9 | # Errors | ||
10 | {"key": value.upper() for value in data} | ||
11 | # Errors | ||
12 | {"key": value.upper() for value in data} | ||
| ^^^^^ RUF011 | ||
11 | {True: value.upper() for value in data} | ||
12 | {0: value.upper() for value in data} | ||
13 | {True: value.upper() for value in data} | ||
14 | {0: value.upper() for value in data} | ||
| | ||
|
||
RUF011.py:11:2: RUF011 Dictionary comprehension uses static key: `True` | ||
RUF011.py:13:2: RUF011 Dictionary comprehension uses static key: `True` | ||
| | ||
9 | # Errors | ||
10 | {"key": value.upper() for value in data} | ||
11 | {True: value.upper() for value in data} | ||
11 | # Errors | ||
12 | {"key": value.upper() for value in data} | ||
13 | {True: value.upper() for value in data} | ||
| ^^^^ RUF011 | ||
12 | {0: value.upper() for value in data} | ||
13 | {(1, "a"): value.upper() for value in data} # constant tuple | ||
14 | {0: value.upper() for value in data} | ||
15 | {(1, "a"): value.upper() for value in data} # Constant tuple | ||
| | ||
|
||
RUF011.py:12:2: RUF011 Dictionary comprehension uses static key: `0` | ||
RUF011.py:14:2: RUF011 Dictionary comprehension uses static key: `0` | ||
| | ||
10 | {"key": value.upper() for value in data} | ||
11 | {True: value.upper() for value in data} | ||
12 | {0: value.upper() for value in data} | ||
12 | {"key": value.upper() for value in data} | ||
13 | {True: value.upper() for value in data} | ||
14 | {0: value.upper() for value in data} | ||
| ^ RUF011 | ||
13 | {(1, "a"): value.upper() for value in data} # constant tuple | ||
15 | {(1, "a"): value.upper() for value in data} # Constant tuple | ||
16 | {constant: value.upper() for value in data} | ||
| | ||
|
||
RUF011.py:13:2: RUF011 Dictionary comprehension uses static key: `(1, "a")` | ||
RUF011.py:15:2: RUF011 Dictionary comprehension uses static key: `(1, "a")` | ||
| | ||
11 | {True: value.upper() for value in data} | ||
12 | {0: value.upper() for value in data} | ||
13 | {(1, "a"): value.upper() for value in data} # constant tuple | ||
13 | {True: value.upper() for value in data} | ||
14 | {0: value.upper() for value in data} | ||
15 | {(1, "a"): value.upper() for value in data} # Constant tuple | ||
| ^^^^^^^^ RUF011 | ||
16 | {constant: value.upper() for value in data} | ||
17 | {constant + constant: value.upper() for value in data} | ||
| | ||
|
||
RUF011.py:16:2: RUF011 Dictionary comprehension uses static key: `constant` | ||
| | ||
14 | {0: value.upper() for value in data} | ||
15 | {(1, "a"): value.upper() for value in data} # Constant tuple | ||
16 | {constant: value.upper() for value in data} | ||
| ^^^^^^^^ RUF011 | ||
17 | {constant + constant: value.upper() for value in data} | ||
| | ||
|
||
RUF011.py:17:2: RUF011 Dictionary comprehension uses static key: `constant + constant` | ||
| | ||
15 | {(1, "a"): value.upper() for value in data} # Constant tuple | ||
16 | {constant: value.upper() for value in data} | ||
17 | {constant + constant: value.upper() for value in data} | ||
| ^^^^^^^^^^^^^^^^^^^ RUF011 | ||
| | ||
|
||
|
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