Skip to content

Commit

Permalink
Revert "fix: out of scope error when "dest" variable is undefined #413"
Browse files Browse the repository at this point in the history
This reverts commit a53d652.
  • Loading branch information
theskumar committed Sep 3, 2022
1 parent b1f041d commit 490b116
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/dotenv/main.py
Expand Up @@ -125,16 +125,15 @@ def rewrite(
path: Union[str, os.PathLike],
encoding: Optional[str],
) -> Iterator[Tuple[IO[str], IO[str]]]:
dest = None
try:
if not os.path.isfile(path):
with open(path, "w+", encoding=encoding) as source:
source.write("")
dest = tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding=encoding)
with open(path, encoding=encoding) as source:
yield (source, dest) # type: ignore
with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding=encoding) as dest:
with open(path, encoding=encoding) as source:
yield (source, dest) # type: ignore
except BaseException:
if dest and os.path.isfile(dest.name):
if os.path.isfile(dest.name):
os.unlink(dest.name)
raise
else:
Expand Down
5 changes: 0 additions & 5 deletions tests/test_main.py
Expand Up @@ -22,11 +22,6 @@ def test_set_key_no_file(tmp_path):
assert os.path.exists(nx_file)


def test_set_key_invalid_file():
with pytest.raises(TypeError):
dotenv.set_key(None, "foo", "bar")


@pytest.mark.parametrize(
"before,key,value,expected,after",
[
Expand Down

0 comments on commit 490b116

Please sign in to comment.