-
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.
## Summary Ensures that we can catch cases like: ```python ages = {"Tom": 23, "Maria": 23, "Dog": 11} age = ages.get("Cat", None) ``` Previously, the rule was somewhat useless, as it only checked for literal accesses. Closes #8760.
- Loading branch information
1 parent
a7fc785
commit 8b86e80
Showing
5 changed files
with
168 additions
and
7 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
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
122 changes: 122 additions & 0 deletions
122
...lify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM910_SIM910.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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs | ||
--- | ||
SIM910.py:2:1: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` | ||
| | ||
1 | # SIM910 | ||
2 | {}.get(key, None) | ||
| ^^^^^^^^^^^^^^^^^ SIM910 | ||
3 | | ||
4 | # SIM910 | ||
| | ||
= help: Replace `{}.get(key, None)` with `{}.get(key)` | ||
|
||
ℹ Safe fix | ||
1 1 | # SIM910 | ||
2 |-{}.get(key, None) | ||
2 |+{}.get(key) | ||
3 3 | | ||
4 4 | # SIM910 | ||
5 5 | {}.get("key", None) | ||
|
||
SIM910.py:5:1: SIM910 [*] Use `{}.get("key")` instead of `{}.get("key", None)` | ||
| | ||
4 | # SIM910 | ||
5 | {}.get("key", None) | ||
| ^^^^^^^^^^^^^^^^^^^ SIM910 | ||
6 | | ||
7 | # OK | ||
| | ||
= help: Replace `{}.get("key", None)` with `{}.get("key")` | ||
|
||
ℹ Safe fix | ||
2 2 | {}.get(key, None) | ||
3 3 | | ||
4 4 | # SIM910 | ||
5 |-{}.get("key", None) | ||
5 |+{}.get("key") | ||
6 6 | | ||
7 7 | # OK | ||
8 8 | {}.get(key) | ||
|
||
SIM910.py:20:9: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` | ||
| | ||
19 | # SIM910 | ||
20 | if a := {}.get(key, None): | ||
| ^^^^^^^^^^^^^^^^^ SIM910 | ||
21 | pass | ||
| | ||
= help: Replace `{}.get(key, None)` with `{}.get(key)` | ||
|
||
ℹ Safe fix | ||
17 17 | {}.get("key", False) | ||
18 18 | | ||
19 19 | # SIM910 | ||
20 |-if a := {}.get(key, None): | ||
20 |+if a := {}.get(key): | ||
21 21 | pass | ||
22 22 | | ||
23 23 | # SIM910 | ||
|
||
SIM910.py:24:5: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` | ||
| | ||
23 | # SIM910 | ||
24 | a = {}.get(key, None) | ||
| ^^^^^^^^^^^^^^^^^ SIM910 | ||
25 | | ||
26 | # SIM910 | ||
| | ||
= help: Replace `{}.get(key, None)` with `{}.get(key)` | ||
|
||
ℹ Safe fix | ||
21 21 | pass | ||
22 22 | | ||
23 23 | # SIM910 | ||
24 |-a = {}.get(key, None) | ||
24 |+a = {}.get(key) | ||
25 25 | | ||
26 26 | # SIM910 | ||
27 27 | ({}).get(key, None) | ||
|
||
SIM910.py:27:1: SIM910 [*] Use `({}).get(key)` instead of `({}).get(key, None)` | ||
| | ||
26 | # SIM910 | ||
27 | ({}).get(key, None) | ||
| ^^^^^^^^^^^^^^^^^^^ SIM910 | ||
28 | | ||
29 | # SIM910 | ||
| | ||
= help: Replace `({}).get(key, None)` with `({}).get(key)` | ||
|
||
ℹ Safe fix | ||
24 24 | a = {}.get(key, None) | ||
25 25 | | ||
26 26 | # SIM910 | ||
27 |-({}).get(key, None) | ||
27 |+({}).get(key) | ||
28 28 | | ||
29 29 | # SIM910 | ||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11} | ||
|
||
SIM910.py:31:7: SIM910 [*] Use `ages.get("Cat")` instead of `ages.get("Cat", None)` | ||
| | ||
29 | # SIM910 | ||
30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11} | ||
31 | age = ages.get("Cat", None) | ||
| ^^^^^^^^^^^^^^^^^^^^^ SIM910 | ||
32 | | ||
33 | # OK | ||
| | ||
= help: Replace `ages.get("Cat", None)` with `ages.get("Cat")` | ||
|
||
ℹ Safe fix | ||
28 28 | | ||
29 29 | # SIM910 | ||
30 30 | ages = {"Tom": 23, "Maria": 23, "Dog": 11} | ||
31 |-age = ages.get("Cat", None) | ||
31 |+age = ages.get("Cat") | ||
32 32 | | ||
33 33 | # OK | ||
34 34 | ages = ["Tom", "Maria", "Dog"] | ||
|
||
|