mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[pep8-naming
]: Ignore methods decorated with @typing.override
(invalid-argument-name
) (#16667)
## Summary This PR stabilizes the preview behavior for `invalid-argument-name` (`N803`) to ignore argument names of functions decorated with `typing.override` because these methods are *out of the authors* control. This behavior was introduced in https://github.com/astral-sh/ruff/pull/15954 and released as part of Ruff 0.9.5 (6th of February). There have been no new issues or PRs since this behavior change (preview) was introduced.
This commit is contained in:
parent
0aded52c40
commit
3d2f2a2f8d
4 changed files with 2 additions and 49 deletions
|
@ -89,7 +89,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::InvalidArgumentName, Path::new("N803.py"))]
|
||||
#[test_case(Rule::InvalidArgumentName, Path::new("N804.py"))]
|
||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!(
|
||||
|
|
|
@ -23,7 +23,7 @@ use crate::checkers::ast::Checker;
|
|||
/// > mixedCase is allowed only in contexts where that’s already the
|
||||
/// > prevailing style (e.g. threading.py), to retain backwards compatibility.
|
||||
///
|
||||
/// In [preview], overridden methods are ignored.
|
||||
/// Methods decorated with `@typing.override` are ignored.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
@ -61,8 +61,7 @@ pub(crate) fn invalid_argument_name_function(checker: &Checker, function_def: &S
|
|||
let semantic = checker.semantic();
|
||||
let scope = semantic.current_scope();
|
||||
|
||||
if checker.settings.preview.is_enabled()
|
||||
&& matches!(scope.kind, ScopeKind::Class(_))
|
||||
if matches!(scope.kind, ScopeKind::Class(_))
|
||||
&& is_override(&function_def.decorator_list, semantic)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -16,14 +16,6 @@ N803.py:6:28: N803 Argument name `A` should be lowercase
|
|||
7 | return _, a, A
|
||||
|
|
||||
|
||||
N803.py:18:28: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
16 | class Extended(Class):
|
||||
17 | @override
|
||||
18 | def method(self, _, a, A): ...
|
||||
| ^ N803
|
||||
|
|
||||
|
||||
N803.py:22:16: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
21 | @override # Incorrect usage
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pep8_naming/mod.rs
|
||||
---
|
||||
N803.py:1:16: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
1 | def func(_, a, A):
|
||||
| ^ N803
|
||||
2 | return _, a, A
|
||||
|
|
||||
|
||||
N803.py:6:28: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
5 | class Class:
|
||||
6 | def method(self, _, a, A):
|
||||
| ^ N803
|
||||
7 | return _, a, A
|
||||
|
|
||||
|
||||
N803.py:22:16: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
21 | @override # Incorrect usage
|
||||
22 | def func(_, a, A): ...
|
||||
| ^ N803
|
||||
|
|
||||
|
||||
N803.py:25:21: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
25 | func = lambda _, a, A: ...
|
||||
| ^ N803
|
||||
|
|
||||
|
||||
N803.py:29:42: N803 Argument name `A` should be lowercase
|
||||
|
|
||||
28 | class Extended(Class):
|
||||
29 | method = override(lambda self, _, a, A: ...) # Incorrect usage
|
||||
| ^ N803
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue