fix(rules): skip dummy variables for PLR1704 (#12190)

## Summary

Resolves #12157.

## Test Plan

Snapshot tests.
This commit is contained in:
Mathieu Kniewallner 2024-07-04 22:09:31 +02:00 committed by GitHub
parent e2e0889a30
commit 2f3264e148
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 69 additions and 63 deletions

View file

@ -21,6 +21,11 @@ else:
print(a)
def func(_):
for _ in range(1):
...
# Errors
def func(a):
for a in range(1):

View file

@ -136,6 +136,9 @@ pub(crate) fn deferred_scopes(checker: &mut Checker) {
if !shadowed.kind.is_argument() {
continue;
}
if checker.settings.dummy_variable_rgx.is_match(name) {
continue;
}
checker.diagnostics.push(Diagnostic::new(
pylint::rules::RedefinedArgumentFromLocal {
name: name.to_string(),

View file

@ -1,60 +1,44 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
redefined_argument_from_local.py:26:9: PLR1704 Redefining argument with the local name `a`
redefined_argument_from_local.py:31:9: PLR1704 Redefining argument with the local name `a`
|
24 | # Errors
25 | def func(a):
26 | for a in range(1):
29 | # Errors
30 | def func(a):
31 | for a in range(1):
| ^ PLR1704
27 | ...
32 | ...
|
redefined_argument_from_local.py:31:9: PLR1704 Redefining argument with the local name `i`
redefined_argument_from_local.py:36:9: PLR1704 Redefining argument with the local name `i`
|
30 | def func(i):
31 | for i in range(10):
35 | def func(i):
36 | for i in range(10):
| ^ PLR1704
32 | print(i)
37 | print(i)
|
redefined_argument_from_local.py:38:25: PLR1704 Redefining argument with the local name `e`
redefined_argument_from_local.py:43:25: PLR1704 Redefining argument with the local name `e`
|
36 | try:
37 | ...
38 | except Exception as e:
41 | try:
42 | ...
43 | except Exception as e:
| ^ PLR1704
39 | print(e)
44 | print(e)
|
redefined_argument_from_local.py:43:24: PLR1704 Redefining argument with the local name `f`
redefined_argument_from_local.py:48:24: PLR1704 Redefining argument with the local name `f`
|
42 | def func(f):
43 | with open('', ) as f:
47 | def func(f):
48 | with open('', ) as f:
| ^ PLR1704
44 | print(f)
|
redefined_argument_from_local.py:48:24: PLR1704 Redefining argument with the local name `a`
|
47 | def func(a, b):
48 | with context() as (a, b, c):
| ^ PLR1704
49 | print(a, b, c)
|
redefined_argument_from_local.py:48:27: PLR1704 Redefining argument with the local name `b`
|
47 | def func(a, b):
48 | with context() as (a, b, c):
| ^ PLR1704
49 | print(a, b, c)
49 | print(f)
|
redefined_argument_from_local.py:53:24: PLR1704 Redefining argument with the local name `a`
|
52 | def func(a, b):
53 | with context() as [a, b, c]:
53 | with context() as (a, b, c):
| ^ PLR1704
54 | print(a, b, c)
|
@ -62,54 +46,68 @@ redefined_argument_from_local.py:53:24: PLR1704 Redefining argument with the loc
redefined_argument_from_local.py:53:27: PLR1704 Redefining argument with the local name `b`
|
52 | def func(a, b):
53 | with context() as [a, b, c]:
53 | with context() as (a, b, c):
| ^ PLR1704
54 | print(a, b, c)
|
redefined_argument_from_local.py:58:51: PLR1704 Redefining argument with the local name `a`
redefined_argument_from_local.py:58:24: PLR1704 Redefining argument with the local name `a`
|
57 | def func(a):
58 | with open('foo.py', ) as f, open('bar.py') as a:
| ^ PLR1704
59 | ...
57 | def func(a, b):
58 | with context() as [a, b, c]:
| ^ PLR1704
59 | print(a, b, c)
|
redefined_argument_from_local.py:64:13: PLR1704 Redefining argument with the local name `a`
redefined_argument_from_local.py:58:27: PLR1704 Redefining argument with the local name `b`
|
57 | def func(a, b):
58 | with context() as [a, b, c]:
| ^ PLR1704
59 | print(a, b, c)
|
redefined_argument_from_local.py:63:51: PLR1704 Redefining argument with the local name `a`
|
62 | def func(a):
63 | def bar(b):
64 | for a in range(1):
63 | with open('foo.py', ) as f, open('bar.py') as a:
| ^ PLR1704
64 | ...
|
redefined_argument_from_local.py:69:13: PLR1704 Redefining argument with the local name `a`
|
67 | def func(a):
68 | def bar(b):
69 | for a in range(1):
| ^ PLR1704
65 | print(a)
70 | print(a)
|
redefined_argument_from_local.py:70:13: PLR1704 Redefining argument with the local name `b`
redefined_argument_from_local.py:75:13: PLR1704 Redefining argument with the local name `b`
|
68 | def func(a):
69 | def bar(b):
70 | for b in range(1):
73 | def func(a):
74 | def bar(b):
75 | for b in range(1):
| ^ PLR1704
71 | print(b)
76 | print(b)
|
redefined_argument_from_local.py:76:13: PLR1704 Redefining argument with the local name `a`
redefined_argument_from_local.py:81:13: PLR1704 Redefining argument with the local name `a`
|
74 | def func(a=1):
75 | def bar(b=2):
76 | for a in range(1):
79 | def func(a=1):
80 | def bar(b=2):
81 | for a in range(1):
| ^ PLR1704
77 | print(a)
78 | for b in range(1):
82 | print(a)
83 | for b in range(1):
|
redefined_argument_from_local.py:78:13: PLR1704 Redefining argument with the local name `b`
redefined_argument_from_local.py:83:13: PLR1704 Redefining argument with the local name `b`
|
76 | for a in range(1):
77 | print(a)
78 | for b in range(1):
81 | for a in range(1):
82 | print(a)
83 | for b in range(1):
| ^ PLR1704
79 | print(b)
84 | print(b)
|