Fix N804 class method with positional only args (#836)

This commit is contained in:
Jonathan Plasse
2022-11-20 21:48:09 +01:00
committed by GitHub
parent 0791869451
commit f96c64b40d
3 changed files with 26 additions and 3 deletions

View File

@@ -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):

View File

@@ -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,

View File

@@ -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: ~