Skip to content

PLR0912: branches inside with statement not counted #11313

@Kakadus

Description

@Kakadus

PLR0912(too-many-branches) does not count branches inside with: blocks. With pylint the following is detected, while ruff does not detect this rule violation

from contextlib import suppress
def capital(country):
    with suppress(Exception):
        if country == "Australia":
            return "Canberra"
        elif country == "Brazil":
            return "Brasilia"
        elif country == "Canada":
            return "Ottawa"
        elif country == "England":
            return "London"
        elif country == "France":
            return "Paris"
        elif country == "Germany":
            return "Berlin"
        elif country == "Poland":
            return "Warsaw"
        elif country == "Romania":
            return "Bucharest"
        elif country == "Spain":
            return "Madrid"
        elif country == "Thailand":
            return "Bangkok"
        elif country == "Turkey":
            return "Ankara"
        elif country == "Undefined":
            return None
        else:
            return "Some"

Ruff version: 0.4.3
command: ruff check test.py --select PLR0912 --isolated

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions