Skip to content

Commit

Permalink
fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Warren committed Feb 20, 2024
1 parent 252462e commit fb6e310
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def from_dict(self, data: Dict[str, Optional[str]], override: bool = False) -> N
)
continue

if not self._dict:
self._dict = OrderedDict()
self._dict[key] = value

def dumps(self) -> str:
Expand All @@ -143,8 +145,10 @@ def dump(self) -> None:
"""
Write the instance to the .env file.
"""
with open(self.dotenv_path, "w", encoding=self.encoding) as f:
f.write(self.dumps())

if self.dotenv_path and os.path.isfile(self.dotenv_path):
with open(self.dotenv_path, "w", encoding=self.encoding) as f:
f.write(self.dumps())


def get_key(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import textwrap
from typing import Dict, Optional
from unittest import mock

import pytest
Expand Down Expand Up @@ -402,7 +403,7 @@ def test_dotenv_values_file_stream(dotenv_path):


def test_from_dict_and_dumps(dotenv_path):
data = {"a": "b", "c": "d"}
data: Dict[str, Optional[str]] = {"a": "b", "c": "d"}

de = dotenv.main.DotEnv(dotenv_path)
de.from_dict(data)
Expand Down

0 comments on commit fb6e310

Please sign in to comment.