summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--isort/api.py2
-rw-r--r--tests/test_api.py1
2 files changed, 2 insertions, 1 deletions
diff --git a/isort/api.py b/isort/api.py
index 4648d77a..8e3e2018 100644
--- a/isort/api.py
+++ b/isort/api.py
@@ -486,7 +486,6 @@ def sort_file(
disregard_skip=disregard_skip,
**config_kwargs,
)
- source_file.stream.close()
if changed:
if show_diff or ask_to_apply:
source_file.stream.seek(0)
@@ -499,6 +498,7 @@ def sort_file(
str(source_file.path)
):
return
+ source_file.stream.close()
tmp_file.replace(source_file.path)
if not config.quiet:
print(f"Fixing {source_file.path}")
diff --git a/tests/test_api.py b/tests/test_api.py
index 44db6e62..bc0a4ffa 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -15,6 +15,7 @@ def test_sort_file(tmpdir) -> None:
imperfect = tmpdir.join(f"test_needs_changes.py")
imperfect.write_text("import b\nimport a\n", "utf8")
api.sort_file(imperfect, write_to_stdout=True, show_diff=True)
+ api.sort_file(imperfect, show_diff=True)
def test_check_file(tmpdir) -> None: