Skip to content

Commit

Permalink
Add a test case for too-complex in match case, for discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed May 22, 2024
1 parent 3bf22d8 commit 1096f19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pylint/extensions/mccabe.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def visitFunctionDef(self, node: nodes.FunctionDef) -> None:

visitAsyncFunctionDef = visitFunctionDef

# def visitMatchCase(self, node: MatchCase) -> None:
# self._append_node(node)

def visitSimpleStatement(self, node: _StatementNodes) -> None:
self._append_node(node)

Expand Down
13 changes: 13 additions & 0 deletions tests/functional/ext/mccabe/mccabe.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,16 @@ def method3(self): # [too-complex]
finally:
pass
return True

def match_case_complexity(self, avg): # [too-complex]
"""McCabe rating: 3
See https://github.com/astral-sh/ruff/issues/11421
"""
match avg:
case avg if avg < .3:
avg_grade = "F"
case avg if avg < .7:
avg_grade = "E+"
case _:
raise ValueError(f"Unexpected average: {avg}")
return avg_grade
1 change: 1 addition & 0 deletions tests/functional/ext/mccabe/mccabe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ too-complex:142:4:142:15:MyClass1.method2:'method2' is too complex. The McCabe r
too-many-branches:142:4:142:15:MyClass1.method2:Too many branches (19/12):UNDEFINED
too-complex:198:0:204:15::This 'for' is too complex. The McCabe rating is 4:HIGH
too-complex:207:0:207:11:method3:'method3' is too complex. The McCabe rating is 3:HIGH
too-complex:218:0:218:25:match_case_complexity:'match_case_complexity' is too complex. The McCabe rating is 3:HIGH

0 comments on commit 1096f19

Please sign in to comment.