Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test case for too-complex in match case, for discussion #9667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading