Avoid panic in unused arguments rule for parameter-free lambda (#6679)

## Summary

This was just a mistake in pattern-matching with no test coverage.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-18 14:29:31 -04:00 committed by GitHub
parent 6a5acde226
commit 053b1145f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 53 deletions

View File

@ -27,6 +27,8 @@ def f(cls, x):
### ###
lambda x: print("Hello, world!") lambda x: print("Hello, world!")
lambda: print("Hello, world!")
class C: class C:
### ###

View File

@ -436,23 +436,22 @@ pub(crate) fn unused_arguments(
} }
} }
} }
ScopeKind::Lambda(ast::ExprLambda { ScopeKind::Lambda(ast::ExprLambda { parameters, .. }) => {
parameters: Some(parameters), if let Some(parameters) = parameters {
.. if checker.enabled(Argumentable::Lambda.rule_code()) {
}) => { function(
if checker.enabled(Argumentable::Lambda.rule_code()) { Argumentable::Lambda,
function( parameters,
Argumentable::Lambda, scope,
parameters, checker.semantic(),
scope, &checker.settings.dummy_variable_rgx,
checker.semantic(), checker
&checker.settings.dummy_variable_rgx, .settings
checker .flake8_unused_arguments
.settings .ignore_variadic_names,
.flake8_unused_arguments diagnostics,
.ignore_variadic_names, );
diagnostics, }
);
} }
} }
_ => panic!("Expected ScopeKind::Function | ScopeKind::Lambda"), _ => panic!("Expected ScopeKind::Function | ScopeKind::Lambda"),

View File

@ -1,40 +1,40 @@
--- ---
source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs
--- ---
ARG.py:35:17: ARG002 Unused method argument: `x` ARG.py:37:17: ARG002 Unused method argument: `x`
| |
33 | # Unused arguments. 35 | # Unused arguments.
34 | ### 36 | ###
35 | def f(self, x): 37 | def f(self, x):
| ^ ARG002 | ^ ARG002
36 | print("Hello, world!") 38 | print("Hello, world!")
| |
ARG.py:38:20: ARG002 Unused method argument: `x` ARG.py:40:20: ARG002 Unused method argument: `x`
| |
36 | print("Hello, world!") 38 | print("Hello, world!")
37 | 39 |
38 | def f(self, /, x): 40 | def f(self, /, x):
| ^ ARG002 | ^ ARG002
39 | print("Hello, world!") 41 | print("Hello, world!")
| |
ARG.py:41:16: ARG002 Unused method argument: `x` ARG.py:43:16: ARG002 Unused method argument: `x`
| |
39 | print("Hello, world!") 41 | print("Hello, world!")
40 | 42 |
41 | def f(cls, x): 43 | def f(cls, x):
| ^ ARG002 | ^ ARG002
42 | print("Hello, world!") 44 | print("Hello, world!")
| |
ARG.py:190:24: ARG002 Unused method argument: `x` ARG.py:192:24: ARG002 Unused method argument: `x`
| |
188 | ### 190 | ###
189 | class C: 191 | class C:
190 | def __init__(self, x) -> None: 192 | def __init__(self, x) -> None:
| ^ ARG002 | ^ ARG002
191 | print("Hello, world!") 193 | print("Hello, world!")
| |

View File

@ -1,12 +1,12 @@
--- ---
source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs
--- ---
ARG.py:45:16: ARG003 Unused class method argument: `x` ARG.py:47:16: ARG003 Unused class method argument: `x`
| |
44 | @classmethod 46 | @classmethod
45 | def f(cls, x): 47 | def f(cls, x):
| ^ ARG003 | ^ ARG003
46 | print("Hello, world!") 48 | print("Hello, world!")
| |

View File

@ -1,28 +1,28 @@
--- ---
source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs
--- ---
ARG.py:49:11: ARG004 Unused static method argument: `cls` ARG.py:51:11: ARG004 Unused static method argument: `cls`
| |
48 | @staticmethod 50 | @staticmethod
49 | def f(cls, x): 51 | def f(cls, x):
| ^^^ ARG004 | ^^^ ARG004
50 | print("Hello, world!") 52 | print("Hello, world!")
| |
ARG.py:49:16: ARG004 Unused static method argument: `x` ARG.py:51:16: ARG004 Unused static method argument: `x`
| |
48 | @staticmethod 50 | @staticmethod
49 | def f(cls, x): 51 | def f(cls, x):
| ^ ARG004 | ^ ARG004
50 | print("Hello, world!") 52 | print("Hello, world!")
| |
ARG.py:53:11: ARG004 Unused static method argument: `x` ARG.py:55:11: ARG004 Unused static method argument: `x`
| |
52 | @staticmethod 54 | @staticmethod
53 | def f(x): 55 | def f(x):
| ^ ARG004 | ^ ARG004
54 | print("Hello, world!") 56 | print("Hello, world!")
| |

View File

@ -7,6 +7,8 @@ ARG.py:28:8: ARG005 Unused lambda argument: `x`
27 | ### 27 | ###
28 | lambda x: print("Hello, world!") 28 | lambda x: print("Hello, world!")
| ^ ARG005 | ^ ARG005
29 |
30 | lambda: print("Hello, world!")
| |