Skip to content

Commit 2f3264e

Browse files
authored
fix(rules): skip dummy variables for PLR1704 (#12190)
## Summary Resolves #12157. ## Test Plan Snapshot tests.
1 parent e2e0889 commit 2f3264e

File tree

3 files changed

+67
-61
lines changed

3 files changed

+67
-61
lines changed

crates/ruff_linter/resources/test/fixtures/pylint/redefined_argument_from_local.py

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def func(a):
2121
print(a)
2222

2323

24+
def func(_):
25+
for _ in range(1):
26+
...
27+
28+
2429
# Errors
2530
def func(a):
2631
for a in range(1):

crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
136136
if !shadowed.kind.is_argument() {
137137
continue;
138138
}
139+
if checker.settings.dummy_variable_rgx.is_match(name) {
140+
continue;
141+
}
139142
checker.diagnostics.push(Diagnostic::new(
140143
pylint::rules::RedefinedArgumentFromLocal {
141144
name: name.to_string(),
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,113 @@
11
---
22
source: crates/ruff_linter/src/rules/pylint/mod.rs
33
---
4-
redefined_argument_from_local.py:26:9: PLR1704 Redefining argument with the local name `a`
4+
redefined_argument_from_local.py:31:9: PLR1704 Redefining argument with the local name `a`
55
|
6-
24 | # Errors
7-
25 | def func(a):
8-
26 | for a in range(1):
6+
29 | # Errors
7+
30 | def func(a):
8+
31 | for a in range(1):
99
| ^ PLR1704
10-
27 | ...
10+
32 | ...
1111
|
1212

13-
redefined_argument_from_local.py:31:9: PLR1704 Redefining argument with the local name `i`
13+
redefined_argument_from_local.py:36:9: PLR1704 Redefining argument with the local name `i`
1414
|
15-
30 | def func(i):
16-
31 | for i in range(10):
15+
35 | def func(i):
16+
36 | for i in range(10):
1717
| ^ PLR1704
18-
32 | print(i)
18+
37 | print(i)
1919
|
2020

21-
redefined_argument_from_local.py:38:25: PLR1704 Redefining argument with the local name `e`
21+
redefined_argument_from_local.py:43:25: PLR1704 Redefining argument with the local name `e`
2222
|
23-
36 | try:
24-
37 | ...
25-
38 | except Exception as e:
23+
41 | try:
24+
42 | ...
25+
43 | except Exception as e:
2626
| ^ PLR1704
27-
39 | print(e)
27+
44 | print(e)
2828
|
2929

30-
redefined_argument_from_local.py:43:24: PLR1704 Redefining argument with the local name `f`
30+
redefined_argument_from_local.py:48:24: PLR1704 Redefining argument with the local name `f`
3131
|
32-
42 | def func(f):
33-
43 | with open('', ) as f:
32+
47 | def func(f):
33+
48 | with open('', ) as f:
3434
| ^ PLR1704
35-
44 | print(f)
35+
49 | print(f)
3636
|
3737

38-
redefined_argument_from_local.py:48:24: PLR1704 Redefining argument with the local name `a`
38+
redefined_argument_from_local.py:53:24: PLR1704 Redefining argument with the local name `a`
3939
|
40-
47 | def func(a, b):
41-
48 | with context() as (a, b, c):
40+
52 | def func(a, b):
41+
53 | with context() as (a, b, c):
4242
| ^ PLR1704
43-
49 | print(a, b, c)
43+
54 | print(a, b, c)
4444
|
4545

46-
redefined_argument_from_local.py:48:27: PLR1704 Redefining argument with the local name `b`
46+
redefined_argument_from_local.py:53:27: PLR1704 Redefining argument with the local name `b`
4747
|
48-
47 | def func(a, b):
49-
48 | with context() as (a, b, c):
48+
52 | def func(a, b):
49+
53 | with context() as (a, b, c):
5050
| ^ PLR1704
51-
49 | print(a, b, c)
51+
54 | print(a, b, c)
5252
|
5353

54-
redefined_argument_from_local.py:53:24: PLR1704 Redefining argument with the local name `a`
54+
redefined_argument_from_local.py:58:24: PLR1704 Redefining argument with the local name `a`
5555
|
56-
52 | def func(a, b):
57-
53 | with context() as [a, b, c]:
56+
57 | def func(a, b):
57+
58 | with context() as [a, b, c]:
5858
| ^ PLR1704
59-
54 | print(a, b, c)
59+
59 | print(a, b, c)
6060
|
6161

62-
redefined_argument_from_local.py:53:27: PLR1704 Redefining argument with the local name `b`
62+
redefined_argument_from_local.py:58:27: PLR1704 Redefining argument with the local name `b`
6363
|
64-
52 | def func(a, b):
65-
53 | with context() as [a, b, c]:
64+
57 | def func(a, b):
65+
58 | with context() as [a, b, c]:
6666
| ^ PLR1704
67-
54 | print(a, b, c)
67+
59 | print(a, b, c)
6868
|
6969

70-
redefined_argument_from_local.py:58:51: PLR1704 Redefining argument with the local name `a`
70+
redefined_argument_from_local.py:63:51: PLR1704 Redefining argument with the local name `a`
7171
|
72-
57 | def func(a):
73-
58 | with open('foo.py', ) as f, open('bar.py') as a:
72+
62 | def func(a):
73+
63 | with open('foo.py', ) as f, open('bar.py') as a:
7474
| ^ PLR1704
75-
59 | ...
75+
64 | ...
7676
|
7777

78-
redefined_argument_from_local.py:64:13: PLR1704 Redefining argument with the local name `a`
78+
redefined_argument_from_local.py:69:13: PLR1704 Redefining argument with the local name `a`
7979
|
80-
62 | def func(a):
81-
63 | def bar(b):
82-
64 | for a in range(1):
80+
67 | def func(a):
81+
68 | def bar(b):
82+
69 | for a in range(1):
8383
| ^ PLR1704
84-
65 | print(a)
84+
70 | print(a)
8585
|
8686

87-
redefined_argument_from_local.py:70:13: PLR1704 Redefining argument with the local name `b`
87+
redefined_argument_from_local.py:75:13: PLR1704 Redefining argument with the local name `b`
8888
|
89-
68 | def func(a):
90-
69 | def bar(b):
91-
70 | for b in range(1):
89+
73 | def func(a):
90+
74 | def bar(b):
91+
75 | for b in range(1):
9292
| ^ PLR1704
93-
71 | print(b)
93+
76 | print(b)
9494
|
9595

96-
redefined_argument_from_local.py:76:13: PLR1704 Redefining argument with the local name `a`
96+
redefined_argument_from_local.py:81:13: PLR1704 Redefining argument with the local name `a`
9797
|
98-
74 | def func(a=1):
99-
75 | def bar(b=2):
100-
76 | for a in range(1):
98+
79 | def func(a=1):
99+
80 | def bar(b=2):
100+
81 | for a in range(1):
101101
| ^ PLR1704
102-
77 | print(a)
103-
78 | for b in range(1):
102+
82 | print(a)
103+
83 | for b in range(1):
104104
|
105105

106-
redefined_argument_from_local.py:78:13: PLR1704 Redefining argument with the local name `b`
106+
redefined_argument_from_local.py:83:13: PLR1704 Redefining argument with the local name `b`
107107
|
108-
76 | for a in range(1):
109-
77 | print(a)
110-
78 | for b in range(1):
108+
81 | for a in range(1):
109+
82 | print(a)
110+
83 | for b in range(1):
111111
| ^ PLR1704
112-
79 | print(b)
112+
84 | print(b)
113113
|
114-
115-

0 commit comments

Comments
 (0)