diff --git a/resources/test/fixtures/N804.py b/resources/test/fixtures/N804.py index 51b2e5f8a4..eb2859ca97 100644 --- a/resources/test/fixtures/N804.py +++ b/resources/test/fixtures/N804.py @@ -30,6 +30,14 @@ class Class: def __init_subclass__(self, default_name, **kwargs): ... + @classmethod + def class_method_with_positional_only_argument(cls, x, /, other): + ... + + @classmethod + def bad_class_method_with_positional_only_argument(self, x, /, other): + ... + class MetaClass(ABCMeta): def bad_method(self): diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/checks.rs index 15b0be482c..048574ebe6 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/checks.rs @@ -74,7 +74,14 @@ pub fn invalid_first_argument_name_for_class_method( ), FunctionType::ClassMethod ) { - if let Some(arg) = args.args.first() { + if let Some(arg) = args.posonlyargs.first() { + if arg.node.arg != "cls" { + return Some(Check::new( + CheckKind::InvalidFirstArgumentNameForClassMethod, + Range::from_located(arg), + )); + } + } else if let Some(arg) = args.args.first() { if arg.node.arg != "cls" { return Some(Check::new( CheckKind::InvalidFirstArgumentNameForClassMethod, diff --git a/src/snapshots/ruff__linter__tests__N804_N804.py.snap b/src/snapshots/ruff__linter__tests__N804_N804.py.snap index 33e04ada47..9e9f45548c 100644 --- a/src/snapshots/ruff__linter__tests__N804_N804.py.snap +++ b/src/snapshots/ruff__linter__tests__N804_N804.py.snap @@ -12,10 +12,18 @@ expression: checks fix: ~ - kind: InvalidFirstArgumentNameForClassMethod location: - row: 35 + row: 38 + column: 55 + end_location: + row: 38 + column: 59 + fix: ~ +- kind: InvalidFirstArgumentNameForClassMethod + location: + row: 43 column: 19 end_location: - row: 35 + row: 43 column: 23 fix: ~