Control statements are nested deeper than the limit

tx0/python:nesting-depthrecommendedwarningmaintainability

What it finds

Control statements are nested deeper than the limit

Example from the rule's tests
def walk(tree, limit):    for node in tree:        if node:            while limit:                with node.lock():                    if node.ready:                        try:tx0 reports: this try in walk is nested 6 levels deep, past the limit of 5                            return node                        finally:                            pass                limit -= 1    return None  def flat(items):    for item in items:        if item:            return item
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:nesting-depth" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:nesting-depth] reason="..."

tx0 explain tx0/python:nesting-depth shows the same in the terminal. Found a false positive? Report it.