File permissions are written in decimal where octal was meant
What it finds
os.chmod(path, 644): permission bits are written in octal, and 644 without the 0o prefix is the decimal number 644, which is 0o1204 and sets the sticky bit and odd permissions instead of rw-r--r--.
Reported are decimal literals of three or four digits from 0 to 7, other than 0, given as the mode to os.chmod, os.fchmod, os.lchmod, os.mkdir, os.makedirs and os.umask. The fix adds the prefix and is safe: a mode that is meant in decimal is not written with digits that only look octal.
From the rule's source, decimal_file_mode.rs.
import os def prepare(path): os.chmod(path, 644)tx0 reports: 644 is a decimal number here; permissions are written 0o644 os.makedirs(path, 755, exist_ok=True)tx0 reports: 755 is a decimal number os.mkdir(path, mode=700)tx0 reports: 700 is a decimal number os.umask(22) os.chmod(path, 0o644) os.chmod(path, 0) os.chmod(path, 384) 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:decimal-file-mode" = "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:decimal-file-mode] reason="..."tx0 explain tx0/python:decimal-file-mode shows the same in the terminal. Found a false positive? Report it.