Accommodate pos-only arguments when checking self name (#2626)

This commit is contained in:
Charlie Marsh 2023-02-07 10:50:50 -05:00 committed by GitHub
parent 2b4ce78830
commit 9fa98ed90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -51,3 +51,11 @@ class MetaClass(ABCMeta):
def func(x):
return x
class PosOnlyClass:
def good_method_pos_only(self, blah, /, something: str):
pass
def bad_method_pos_only(this, blah, /, self, something: str):
pass

View File

@ -316,7 +316,7 @@ pub fn invalid_first_argument_name_for_method(
) {
return None;
}
let arg = args.args.first()?;
let arg = args.posonlyargs.first().or_else(|| args.args.first())?;
if arg.node.arg == "self" {
return None;
}

View File

@ -1,5 +1,5 @@
---
source: src/rules/pep8_naming/mod.rs
source: crates/ruff/src/rules/pep8_naming/mod.rs
expression: diagnostics
---
- kind:
@ -42,4 +42,14 @@ expression: diagnostics
column: 17
fix: ~
parent: ~
- kind:
InvalidFirstArgumentNameForMethod: ~
location:
row: 60
column: 28
end_location:
row: 60
column: 32
fix: ~
parent: ~