Skip to content

Commit 1096f19

Browse files
Add a test case for too-complex in match case, for discussion
1 parent 3bf22d8 commit 1096f19

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pylint/extensions/mccabe.py

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def visitFunctionDef(self, node: nodes.FunctionDef) -> None:
9191

9292
visitAsyncFunctionDef = visitFunctionDef
9393

94+
# def visitMatchCase(self, node: MatchCase) -> None:
95+
# self._append_node(node)
96+
9497
def visitSimpleStatement(self, node: _StatementNodes) -> None:
9598
self._append_node(node)
9699

tests/functional/ext/mccabe/mccabe.py

+13
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,16 @@ def method3(self): # [too-complex]
214214
finally:
215215
pass
216216
return True
217+
218+
def match_case_complexity(self, avg): # [too-complex]
219+
"""McCabe rating: 3
220+
See https://github.com/astral-sh/ruff/issues/11421
221+
"""
222+
match avg:
223+
case avg if avg < .3:
224+
avg_grade = "F"
225+
case avg if avg < .7:
226+
avg_grade = "E+"
227+
case _:
228+
raise ValueError(f"Unexpected average: {avg}")
229+
return avg_grade

tests/functional/ext/mccabe/mccabe.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ too-complex:142:4:142:15:MyClass1.method2:'method2' is too complex. The McCabe r
1313
too-many-branches:142:4:142:15:MyClass1.method2:Too many branches (19/12):UNDEFINED
1414
too-complex:198:0:204:15::This 'for' is too complex. The McCabe rating is 4:HIGH
1515
too-complex:207:0:207:11:method3:'method3' is too complex. The McCabe rating is 3:HIGH
16+
too-complex:218:0:218:25:match_case_complexity:'match_case_complexity' is too complex. The McCabe rating is 3:HIGH

0 commit comments

Comments
 (0)