This rule raises an issue when a file permission mode is passed as a non-octal integer literal to APIs such as
os.chmod.
Using non-octal values to set Unix file permissions is problematic because they are converted to octal internally, which can lead to unexpected file permissions and potential security issues.
Naming the value does not change this. A constant or an immutable local binding initialized with a decimal literal is converted the same way, and
the missing 0o prefix is easier to overlook when the value is declared away from the call.
Write permission modes as octal literals with the 0o prefix so the value matches the intended Unix mode.
The literal 0 is clear on its own and does not need an octal prefix.
Intentional decimal mode literals are rare. Treat them as won’t-fix only after review confirms the decimal value is deliberate rather than a mistaken shell-style octal.
import os
os.chmod("file.txt", 755) # Noncompliant
import os
os.chmod("file.txt", 0o755)
from pathlib import Path
Path("config.ini").chmod(644) # Noncompliant
from pathlib import Path
Path("config.ini").chmod(0o644)
os.chmodpathlib.Path.chmod