A function's branches and loops, weighted by how deep they nest, exceed the configured limit
What it finds
Branches inside branches are harder to read than the same number one after another. This rule weighs each if, for, while, except, match, conditional expression and comprehension by its depth: it adds one, plus one for each of these structures and each lambda that encloses it in the function. elif and else add one each, and so does each chain of the same boolean operator, so a and b and c adds one and a and b or c two. Functions defined inside are measured on their own.
From the rule's source, tangled_function.rs.
def tangled(rows, log):tx0 reports: tangled has a nesting-weighted complexity of 26, more than 25 for row in rows: if row: for cell in row: if cell and cell.ok: while cell.next: if cell.x: log(cell) elif cell.y: log(1) else: log(2) elif row is None: log(0) else: log(3) def flat(rows, log): if rows: log(1) if rows and log: log(2) for row in rows: log(row) while rows: rows = rows[1:] 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:
[rules]
"tx0/python:tangled-function" = "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:tangled-function] reason="..."tx0 explain tx0/python:tangled-function shows the same in the terminal. Found a false positive? Report it.