ruff: Fix SIM115 Use a context manager for opening files.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-10-17 17:59:35 -07:00
committed by Tim Abbott
parent 10271fb850
commit 71ca928ec9
3 changed files with 25 additions and 22 deletions

View File

@@ -24,9 +24,9 @@ def renumber_migration(conflicts: list[str], order: list[int], last_correct_migr
stack.append(conflicts[i - 1][0:4])
else:
# Replace dependencies with the last correct migration
file = fileinput.FileInput("zerver/migrations/" + conflicts[i - 1], inplace=True)
for line in file:
print(re.sub(r"[\d]+(_[a-z0-9]+)+", last_correct_migration, line), end="")
with fileinput.FileInput("zerver/migrations/" + conflicts[i - 1], inplace=True) as file:
for line in file:
print(re.sub(r"[\d]+(_[a-z0-9]+)+", last_correct_migration, line), end="")
# Rename the migration indexing at the end
new_name = conflicts[i - 1].replace(