Skip to content

Commit 955e2a4

Browse files
committed
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.
1 parent f5d0c54 commit 955e2a4

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- The `dotenv_path` argument of `set_key` and `unset_key` now has a type of `Union[str,
13+
os.PathLike]` instead of just `os.PathLike` (#347 by [@bbc2]).
14+
1015
### Changed
1116

1217
- Require Python 3.5 or a later version. Python 2 and 3.4 are no longer supported. (#341

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ max-line-length = 120
1414
exclude = .tox,.git,docs,venv,.venv
1515

1616
[mypy]
17+
check_untyped_defs = true
1718
ignore_missing_imports = true
1819

1920
[metadata]

src/dotenv/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_key(dotenv_path: Union[str, _PathLike], key_to_get: str) -> Optional[str
114114

115115

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

132132

133133
def set_key(
134-
dotenv_path: _PathLike,
134+
dotenv_path: Union[str, _PathLike],
135135
key_to_set: str,
136136
value_to_set: str,
137137
quote_mode: str = "always",
@@ -175,7 +175,7 @@ def set_key(
175175

176176

177177
def unset_key(
178-
dotenv_path: _PathLike,
178+
dotenv_path: Union[str, _PathLike],
179179
key_to_unset: str,
180180
quote_mode: str = "always",
181181
) -> Tuple[Optional[bool], str]:

0 commit comments

Comments
 (0)