Skip to content

Commit

Permalink
Enable checking of "untyped defs" and fix types
Browse files Browse the repository at this point in the history
`set_key` and `unset_key` were more restrictive than other functions
such as `dotenv_values` with regards to their `dotenv_path` argument.
  • Loading branch information
bbc2 committed Jul 14, 2021
1 parent f5d0c54 commit 955e2a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- The `dotenv_path` argument of `set_key` and `unset_key` now has a type of `Union[str,
os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).

### Changed

- Require Python 3.5 or a later version. Python 2 and 3.4 are no longer supported. (#341
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ max-line-length = 120
exclude = .tox,.git,docs,venv,.venv

[mypy]
check_untyped_defs = true
ignore_missing_imports = true

[metadata]
Expand Down
6 changes: 3 additions & 3 deletions src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_key(dotenv_path: Union[str, _PathLike], key_to_get: str) -> Optional[str


@contextmanager
def rewrite(path: _PathLike) -> Iterator[Tuple[IO[str], IO[str]]]:
def rewrite(path: Union[str, _PathLike]) -> Iterator[Tuple[IO[str], IO[str]]]:
try:
if not os.path.isfile(path):
with io.open(path, "w+") as source:
Expand All @@ -131,7 +131,7 @@ def rewrite(path: _PathLike) -> Iterator[Tuple[IO[str], IO[str]]]:


def set_key(
dotenv_path: _PathLike,
dotenv_path: Union[str, _PathLike],
key_to_set: str,
value_to_set: str,
quote_mode: str = "always",
Expand Down Expand Up @@ -175,7 +175,7 @@ def set_key(


def unset_key(
dotenv_path: _PathLike,
dotenv_path: Union[str, _PathLike],
key_to_unset: str,
quote_mode: str = "always",
) -> Tuple[Optional[bool], str]:
Expand Down

0 comments on commit 955e2a4

Please sign in to comment.