Fix N804 class method with positional only args (#836)
This commit is contained in:
8
resources/test/fixtures/N804.py
vendored
8
resources/test/fixtures/N804.py
vendored
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user