bad-open-mode / W1501#

Message emitted:

"%s" is not a valid mode for open.

Description:

Python supports: r, w, a[, x] modes with b, +, and U (only with r) options. See https://docs.python.org/3/library/functions.html#open

Correct code:

def foo(file_path):
    with open(file_path, "r") as file:
        contents = file.read()

Problematic code:

def foo(file_path):
    with open(file_path, "rwx") as file:  # [bad-open-mode]
        contents = file.read()

Created by the stdlib checker.