python: Remove default "r" mode for open().

Generated automatically by pyupgrade.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-08-02 14:19:49 -07:00 committed by Tim Abbott
parent 2bd635853b
commit 1760897a8c
5 changed files with 8 additions and 8 deletions

View File

@ -34,11 +34,11 @@ def generate_sha1sum_node_modules(
PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, "package.json") PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, "package.json")
YARN_LOCK_FILE_PATH = os.path.join(setup_dir, "yarn.lock") YARN_LOCK_FILE_PATH = os.path.join(setup_dir, "yarn.lock")
data: Dict[str, object] = {} data: Dict[str, object] = {}
with open(PACKAGE_JSON_FILE_PATH, "r") as f: with open(PACKAGE_JSON_FILE_PATH) as f:
data[PACKAGE_JSON_FILE_PATH] = f.read().strip() data[PACKAGE_JSON_FILE_PATH] = f.read().strip()
if os.path.exists(YARN_LOCK_FILE_PATH): if os.path.exists(YARN_LOCK_FILE_PATH):
# For backwards compatibility, we can't assume yarn.lock exists # For backwards compatibility, we can't assume yarn.lock exists
with open(YARN_LOCK_FILE_PATH, "r") as f: with open(YARN_LOCK_FILE_PATH) as f:
data[YARN_LOCK_FILE_PATH] = f.read().strip() data[YARN_LOCK_FILE_PATH] = f.read().strip()
with open(YARN_PACKAGE_JSON) as f: with open(YARN_PACKAGE_JSON) as f:
data["yarn-package-version"] = json.load(f)["version"] data["yarn-package-version"] = json.load(f)["version"]

View File

@ -18,7 +18,7 @@ PUPPET_THIRDPARTY = os.path.join(PUPPET_MODULES_CACHE_PATH, "current")
def generate_sha1sum_puppet_modules() -> str: def generate_sha1sum_puppet_modules() -> str:
data = {} data = {}
with open(PUPPET_DEPS_FILE_PATH, "r") as fb: with open(PUPPET_DEPS_FILE_PATH) as fb:
data["deps.yaml"] = fb.read().strip() data["deps.yaml"] = fb.read().strip()
data["puppet-version"] = subprocess.check_output( data["puppet-version"] = subprocess.check_output(
# This is 10x faster than `puppet --version` # This is 10x faster than `puppet --version`
@ -57,7 +57,7 @@ def do_puppet_module_install(
puppet_env["RUBYOPT"] = "-W0" puppet_env["RUBYOPT"] = "-W0"
os.makedirs(target_path, exist_ok=True) os.makedirs(target_path, exist_ok=True)
with open(PUPPET_DEPS_FILE_PATH, "r") as yaml_file: with open(PUPPET_DEPS_FILE_PATH) as yaml_file:
deps = yaml.safe_load(yaml_file) deps = yaml.safe_load(yaml_file)
for module, version in deps.items(): for module, version in deps.items():
run( run(

View File

@ -17,7 +17,7 @@ if len(sys.argv) >= 2:
current_path = sys.argv[1] current_path = sys.argv[1]
print(f"Reading current configuration from {current_path}...") print(f"Reading current configuration from {current_path}...")
with open(current_path, "r") as f: with open(current_path) as f:
current_contents = f.read() current_contents = f.read()
import requests import requests

View File

@ -75,7 +75,7 @@ if not args.noop and not args.force:
env=puppet_env, env=puppet_env,
) )
with open(lastrun_file.name, "r") as lastrun: with open(lastrun_file.name) as lastrun:
lastrun_data = yaml.safe_load(lastrun) lastrun_data = yaml.safe_load(lastrun)
if lastrun_data.get("resources", {}).get("out_of_sync", 0) == 0: if lastrun_data.get("resources", {}).get("out_of_sync", 0) == 0:
sys.exit(0) sys.exit(0)

View File

@ -41,7 +41,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
rest_endpoints_path = os.path.join( rest_endpoints_path = os.path.join(
settings.DEPLOY_ROOT, "templates/zerver/help/include/rest-endpoints.md" settings.DEPLOY_ROOT, "templates/zerver/help/include/rest-endpoints.md"
) )
rest_endpoints_raw = open(rest_endpoints_path, "r").read() rest_endpoints_raw = open(rest_endpoints_path).read()
ENDPOINT_REGEXP = re.compile(r"/api/\s*(.*?)\)") ENDPOINT_REGEXP = re.compile(r"/api/\s*(.*?)\)")
endpoint_list = sorted(set(re.findall(ENDPOINT_REGEXP, rest_endpoints_raw))) endpoint_list = sorted(set(re.findall(ENDPOINT_REGEXP, rest_endpoints_raw)))
@ -51,7 +51,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
curl_commands_to_test = [] curl_commands_to_test = []
if os.path.exists(file_name): if os.path.exists(file_name):
f = open(file_name, "r") f = open(file_name)
for line in f: for line in f:
# A typical example from the Markdown source looks like this: # A typical example from the Markdown source looks like this:
# {generate_code_example(curl, ...} # {generate_code_example(curl, ...}