diff --git a/doc/whatsnew/fragments/10542.false_negative b/doc/whatsnew/fragments/10542.false_negative new file mode 100644 index 0000000000..bd523e53bc --- /dev/null +++ b/doc/whatsnew/fragments/10542.false_negative @@ -0,0 +1,3 @@ +Count match cases for ``too-many-branches`` check. + +Refs #10542 diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index 5c1adbc888..efadbd8c45 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -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 diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index 51cf4e07ea..3ce61af133 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -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: diff --git a/tests/functional/t/too/too_many_branches.py b/tests/functional/t/too/too_many_branches.py index d7a3913e41..ad2d2fb119 100644 --- a/tests/functional/t/too/too_many_branches.py +++ b/tests/functional/t/too/too_many_branches.py @@ -10,10 +10,6 @@ def wrong(): # [too-many-branches] pass elif 1: pass - elif 1: - pass - elif 1: - pass try: pass except TypeError: @@ -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: