int or float is given a string literal it cannot read as a number
What it finds
int("1.5"), float("1,5"), int("0x1f"): converting a string literal that is not a number in the form the function reads raises ValueError every time. int reads whole numbers in base 10 unless given a base, and float reads a decimal point, not a comma.
Checked are string literals given to int without a base, and to float, with Python's own rules for spaces, signs, underscores and the special values of float.
From the rule's source, unparsable_number_literal.rs.
def parse(text): a = int("1.5")tx0 reports: as a number, so this raises ValueError b = float("1,5")tx0 reports: float cannot read c = int("0x1f")tx0 reports: int cannot read d = int("0x1f", 16) e = int(" 42 ") f = float("inf") g = float("1e-3") h = int(text) return a, b, c, d, e, f, g, h Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:unparsable-number-literal" = "off"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:unparsable-number-literal] reason="..."tx0 explain tx0/python:unparsable-number-literal shows the same in the terminal. Found a false positive? Report it.