Skip to content
Merged
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 doc/whatsnew/fragments/10542.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Count match cases for ``too-many-branches`` check.

Refs #10542
5 changes: 5 additions & 0 deletions pylint/checkers/design_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ def visit_while(self, node: nodes.While) -> None:

visit_for = visit_while

def visit_match(self, node: nodes.Match) -> None:
"""Increments the branches counter."""
self._inc_all_stmts(1)
self._inc_branch(node, len(node.cases))

def _inc_branch(self, node: nodes.NodeNG, branchesnum: int = 1) -> None:
"""Increments the branches counter."""
self._branches[node.scope()] += branchesnum
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def new_line(self, tokens: TokenWrapper, line_end: int, line_start: int) -> None
def process_module(self, node: nodes.Module) -> None:
pass

# pylint: disable-next = too-many-return-statements
# pylint: disable-next = too-many-return-statements, too-many-branches
def _check_keyword_parentheses(
self, tokens: list[tokenize.TokenInfo], start: int
) -> None:
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/t/too/too_many_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ def wrong(): # [too-many-branches]
pass
elif 1:
pass
elif 1:
pass
elif 1:
pass
try:
pass
except TypeError:
Expand All @@ -24,6 +20,11 @@ def wrong(): # [too-many-branches]
pass
while True:
pass
match 1:
case 1:
pass
case 2:
pass
if 1:
pass
elif 2:
Expand Down
Loading