Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix FURB122 Use of `f.write` in a for loop.

Anders Kaseorgf990a1400fa5
diff --git a/tools/droplets/add_mentor.py b/tools/droplets/add_mentor.py
index 942e5c13066..53974773d68 100644
--- a/tools/droplets/add_mentor.py
+++ b/tools/droplets/add_mentor.py
@@ -66,8 +66,7 @@ if __name__ == "__main__":
else:
keys = get_mentor_keys(args.username)
with open(authorized_keys, "a") as f:
- for key in keys:
- f.write(append_key.format(username=args.username, key=key))
+ f.writelines(append_key.format(username=args.username, key=key) for key in keys)
print(f"Successfully added {args.username}'s SSH key!")
print("Can you let your mentor know that they can connect to this machine with:\n")
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
index 0db98b006d3..8173e3b38f7 100644
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -571,8 +571,7 @@ def write_instrumentation_reports(full_suite: bool, include_webhooks: bool) -> N
var_dir = "var" # TODO make sure path is robust here
fn = os.path.join(var_dir, "url_coverage.txt")
with open(fn, "wb") as f:
- for call in calls:
- f.write(orjson.dumps(call, option=orjson.OPT_APPEND_NEWLINE))
+ f.writelines(orjson.dumps(call, option=orjson.OPT_APPEND_NEWLINE) for call in calls)
if full_suite:
print(f"INFO: URL coverage report is in {fn}")
diff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.py
index 0f15bed56b9..c00323a265c 100644
--- a/zerver/lib/test_runner.py
+++ b/zerver/lib/test_runner.py
@@ -302,8 +302,7 @@ class Runner(DiscoverRunner):
os.makedirs(os.path.dirname(filepath), exist_ok=True)
with open(filepath, "w") as f:
if self.parallel > 1:
- for index in range(self.parallel):
- f.write(get_database_id(index + 1) + "\n")
+ f.writelines(get_database_id(index + 1) + "\n" for index in range(self.parallel))
else:
f.write(get_database_id() + "\n")