Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type checking with Mypy #347

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pytest-cov
pytest>=3.9
sh>=1.09
tox
types-mock
wheel
twine
portray
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
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ commands = coverage run --parallel -m pytest {posargs}
skip_install = true
deps =
flake8
mypy<0.900
mypy
types-mock
commands =
flake8 src tests
mypy --python-version=3.9 src tests
Expand Down