math.isclose compares with zero without abs_tol, so only exact zero passes
What it finds
math.isclose(x, 0): without abs_tol, isclose only allows a difference relative to the size of the values, and relative to zero that is zero, so the test is true only for exactly 0.0. A small abs_tol says how close to zero counts.
From the rule's source, isclose_without_abs_tol.rs.
import math def near(x, y): a = math.isclose(x, 0)tx0 reports: relative to zero no difference is allowed, so only exact zero is close b = math.isclose(0.0, y)tx0 reports: relative to zero no difference is allowed c = math.isclose(x, 0, abs_tol=1e-9) d = math.isclose(x, y) return a, b, c, d 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:isclose-without-abs-tol" = "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:isclose-without-abs-tol] reason="..."tx0 explain tx0/python:isclose-without-abs-tol shows the same in the terminal. Found a false positive? Report it.