From 955e2a4ea6391a322c779e737f5a7aca7eaa963d Mon Sep 17 00:00:00 2001 From: Bertrand Bonnefoy-Claudet Date: Wed, 14 Jul 2021 09:54:39 +0200 Subject: [PATCH] Enable checking of "untyped defs" and fix types `set_key` and `unset_key` were more restrictive than other functions such as `dotenv_values` with regards to their `dotenv_path` argument. --- CHANGELOG.md | 5 +++++ setup.cfg | 1 + src/dotenv/main.py | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b4340c1..f52cf07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/setup.cfg b/setup.cfg index 9afbc4b3..2723d8a2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,6 +14,7 @@ max-line-length = 120 exclude = .tox,.git,docs,venv,.venv [mypy] +check_untyped_defs = true ignore_missing_imports = true [metadata] diff --git a/src/dotenv/main.py b/src/dotenv/main.py index 6b29fc90..d550f6f8 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -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: @@ -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", @@ -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]: