Skip to content

Commit 90c09a3

Browse files
authored
Count match cases for too-many-branches (#10542)
1 parent 300cb79 commit 90c09a3

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Count match cases for ``too-many-branches`` check.
2+
3+
Refs #10542

pylint/checkers/design_analysis.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,11 @@ def visit_while(self, node: nodes.While) -> None:
693693

694694
visit_for = visit_while
695695

696+
def visit_match(self, node: nodes.Match) -> None:
697+
"""Increments the branches counter."""
698+
self._inc_all_stmts(1)
699+
self._inc_branch(node, len(node.cases))
700+
696701
def _inc_branch(self, node: nodes.NodeNG, branchesnum: int = 1) -> None:
697702
"""Increments the branches counter."""
698703
self._branches[node.scope()] += branchesnum

pylint/checkers/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def new_line(self, tokens: TokenWrapper, line_end: int, line_start: int) -> None
272272
def process_module(self, node: nodes.Module) -> None:
273273
pass
274274

275-
# pylint: disable-next = too-many-return-statements
275+
# pylint: disable-next = too-many-return-statements, too-many-branches
276276
def _check_keyword_parentheses(
277277
self, tokens: list[tokenize.TokenInfo], start: int
278278
) -> None:

tests/functional/t/too/too_many_branches.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ def wrong(): # [too-many-branches]
1010
pass
1111
elif 1:
1212
pass
13-
elif 1:
14-
pass
15-
elif 1:
16-
pass
1713
try:
1814
pass
1915
except TypeError:
@@ -24,6 +20,11 @@ def wrong(): # [too-many-branches]
2420
pass
2521
while True:
2622
pass
23+
match 1:
24+
case 1:
25+
pass
26+
case 2:
27+
pass
2728
if 1:
2829
pass
2930
elif 2:

0 commit comments

Comments
 (0)