A file is opened in text mode without an encoding, so it is read with the platform's default

tx0/python:open-without-encodingstrictnotebug

What it finds

Without encoding=, open decodes text with the locale's encoding, which is UTF-8 on most Linux systems and often cp1252 on Windows, so a file written on one machine may not read on another. Reported are calls of the builtin open in text mode, that is without b in a literal mode, that give no encoding and pass no **kwargs.

From the rule's source, open_without_encoding.rs.

Example from the rule's tests
def read(path, mode):    a = open(path)tx0 reports: this file is opened in text mode without encoding=    b = open(path, "w")tx0 reports: this file is opened in text mode    c = open(path, "rb")    d = open(path, encoding="utf-8")    e = open(path, mode)    f = open(path, mode="wb")    return a, b, c, d, e, f
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:open-without-encoding" = "note"

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:open-without-encoding] reason="..."

tx0 explain tx0/python:open-without-encoding shows the same in the terminal. Found a false positive? Report it.