Skip to content

Commit 490b116

Browse files
committed
Revert "fix: out of scope error when "dest" variable is undefined #413"
This reverts commit a53d652.
1 parent b1f041d commit 490b116

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/dotenv/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,15 @@ def rewrite(
125125
path: Union[str, os.PathLike],
126126
encoding: Optional[str],
127127
) -> Iterator[Tuple[IO[str], IO[str]]]:
128-
dest = None
129128
try:
130129
if not os.path.isfile(path):
131130
with open(path, "w+", encoding=encoding) as source:
132131
source.write("")
133-
dest = tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding=encoding)
134-
with open(path, encoding=encoding) as source:
135-
yield (source, dest) # type: ignore
132+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, encoding=encoding) as dest:
133+
with open(path, encoding=encoding) as source:
134+
yield (source, dest) # type: ignore
136135
except BaseException:
137-
if dest and os.path.isfile(dest.name):
136+
if os.path.isfile(dest.name):
138137
os.unlink(dest.name)
139138
raise
140139
else:

tests/test_main.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ def test_set_key_no_file(tmp_path):
2222
assert os.path.exists(nx_file)
2323

2424

25-
def test_set_key_invalid_file():
26-
with pytest.raises(TypeError):
27-
dotenv.set_key(None, "foo", "bar")
28-
29-
3025
@pytest.mark.parametrize(
3126
"before,key,value,expected,after",
3227
[

0 commit comments

Comments
 (0)