Avoid incrementing McCabe complexity for class methods (#857)
This commit is contained in:
30
resources/test/fixtures/C901.py
vendored
30
resources/test/fixtures/C901.py
vendored
@@ -106,3 +106,33 @@ async def foobar(a, b, c):
|
||||
# Complexity = 1
|
||||
def annotated_assign():
|
||||
x: Any = None
|
||||
|
||||
|
||||
# Complexity = 9
|
||||
class Class:
|
||||
def handle(self, *args, **options):
|
||||
if args:
|
||||
return
|
||||
|
||||
class ServiceProvider:
|
||||
def a(self):
|
||||
pass
|
||||
|
||||
def b(self, data):
|
||||
if not args:
|
||||
pass
|
||||
|
||||
class Logger:
|
||||
def c(*args, **kwargs):
|
||||
pass
|
||||
|
||||
def error(self, message):
|
||||
pass
|
||||
|
||||
def info(self, message):
|
||||
pass
|
||||
|
||||
def exception(self):
|
||||
pass
|
||||
|
||||
return ServiceProvider(Logger())
|
||||
|
||||
@@ -46,7 +46,6 @@ fn get_complexity_number(stmts: &[Stmt]) -> usize {
|
||||
complexity += get_complexity_number(body);
|
||||
}
|
||||
StmtKind::ClassDef { body, .. } => {
|
||||
complexity += 1;
|
||||
complexity += get_complexity_number(body);
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -164,7 +164,84 @@ expression: checks
|
||||
row: 107
|
||||
column: 0
|
||||
end_location:
|
||||
row: 109
|
||||
row: 112
|
||||
column: 0
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- handle
|
||||
- 9
|
||||
location:
|
||||
row: 113
|
||||
column: 4
|
||||
end_location:
|
||||
row: 139
|
||||
column: 0
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- a
|
||||
- 1
|
||||
location:
|
||||
row: 118
|
||||
column: 12
|
||||
end_location:
|
||||
row: 121
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- b
|
||||
- 2
|
||||
location:
|
||||
row: 121
|
||||
column: 12
|
||||
end_location:
|
||||
row: 125
|
||||
column: 8
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- c
|
||||
- 1
|
||||
location:
|
||||
row: 126
|
||||
column: 12
|
||||
end_location:
|
||||
row: 129
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- error
|
||||
- 1
|
||||
location:
|
||||
row: 129
|
||||
column: 12
|
||||
end_location:
|
||||
row: 132
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- info
|
||||
- 1
|
||||
location:
|
||||
row: 132
|
||||
column: 12
|
||||
end_location:
|
||||
row: 135
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- exception
|
||||
- 1
|
||||
location:
|
||||
row: 135
|
||||
column: 12
|
||||
end_location:
|
||||
row: 138
|
||||
column: 8
|
||||
fix: ~
|
||||
|
||||
|
||||
@@ -13,4 +13,15 @@ expression: checks
|
||||
row: 85
|
||||
column: 0
|
||||
fix: ~
|
||||
- kind:
|
||||
FunctionIsTooComplex:
|
||||
- handle
|
||||
- 9
|
||||
location:
|
||||
row: 113
|
||||
column: 4
|
||||
end_location:
|
||||
row: 139
|
||||
column: 0
|
||||
fix: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user