A file is opened with a mode or arguments that open refuses

tx0/python:open-modedefaultwarningbug

What it finds

open(path, "rw"), open(path, "rb", encoding="utf-8"): open accepts a mode made of one of r, w, x and a, optionally +, and at most one of b and t, each once. Any other mode raises ValueError, and so does an encoding, errors or newline other than None given with a binary mode.

Only modes written as string literals are checked, for the builtin open, io.open and os.fdopen.

From the rule's source, open_mode.rs.

Example from the rule's tests
import os  def files(path, fd, mode):    a = open(path, "rw")tx0 reports: open refuses the mode rw: it needs exactly one of r, w, x and a    b = open(path, "rbt")tx0 reports: it cannot be both binary and text    c = open(path, "rb", encoding="utf-8")tx0 reports: open refuses encoding with the binary mode rb    d = os.fdopen(fd, "wq")tx0 reports: os.fdopen refuses the mode wq: q is not a mode character    e = open(path, "rU")tx0 reports: the mode U was removed    f = open(path, "r+b", encoding=None)    g = open(path, mode)    h = open(path, "a+", encoding="utf-8")    return a, b, c, d, e, f, g, h
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:open-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:open-mode] reason="..."

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