diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index 9489f24d6c..b2df5140af 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -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) diff --git a/tests/functional/ext/mccabe/mccabe.py b/tests/functional/ext/mccabe/mccabe.py index 2c6d57a70b..9affaf01fd 100644 --- a/tests/functional/ext/mccabe/mccabe.py +++ b/tests/functional/ext/mccabe/mccabe.py @@ -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 diff --git a/tests/functional/ext/mccabe/mccabe.txt b/tests/functional/ext/mccabe/mccabe.txt index 3ff80e86cd..e0dd2dd0f0 100644 --- a/tests/functional/ext/mccabe/mccabe.txt +++ b/tests/functional/ext/mccabe/mccabe.txt @@ -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