Skip to content

Commit

Permalink
refactor: update type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pivoshenko committed Jun 22, 2024
1 parent c29ffb9 commit d28e69d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/poetry_plugin_dotenv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""poetry-plugin-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run."""

from __future__ import annotations


__title__ = "poetry-plugin-dotenv"
__summary__ = "poetry-plugin-dotenv - is the plugin that automatically loads environment variables from a dotenv file into the environment before poetry commands are run."
__uri__ = "/~https://github.com/pivoshenko/poetry-plugin-dotenv"
Expand Down
6 changes: 6 additions & 0 deletions src/poetry_plugin_dotenv/dotenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
References
----------
#. `python-dotenv </~https://github.com/theskumar/python-dotenv>`_
"""

from __future__ import annotations

from poetry_plugin_dotenv.dotenv import core
from poetry_plugin_dotenv.dotenv import parsers
from poetry_plugin_dotenv.dotenv import variables


__all__ = ["core", "parsers", "variables"]
10 changes: 4 additions & 6 deletions src/poetry_plugin_dotenv/dotenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


if TYPE_CHECKING: # pragma: no cover
from collections.abc import Generator
from collections.abc import Iterable
from collections.abc import Iterator

Expand Down Expand Up @@ -57,15 +56,15 @@ def dict(self) -> OrderedDict[str, str]:
else:
self._dict = OrderedDict(raw_values)

return self._dict # type: ignore[return-value]
return self._dict

def parse(self) -> Generator:
def parse(self) -> Iterator[tuple[str, str]]:
"""Parse a dotenv file."""

with self._get_stream() as stream:
for mapping in parsers.parse_stream(stream):
if mapping.key is not None:
yield mapping.key, mapping.value
yield mapping.key, mapping.value # type: ignore[misc]

def set_as_environment_variables(self) -> bool:
"""Load current dotenv as a system environment variable."""
Expand Down Expand Up @@ -124,7 +123,7 @@ def resolve(

result = "".join(atom.resolve(env) for atom in atoms)

new_values[name] = result # type: ignore[assignment]
new_values[name] = result

return new_values

Expand Down Expand Up @@ -159,7 +158,6 @@ def find(filename: str = ".env", *, usecwd: bool = False) -> str:
current_file = __file__

while frame.f_code.co_filename == current_file:
# S101 - this asserts is part of the original package
assert frame.f_back is not None # noqa: S101
frame = frame.f_back

Expand Down
4 changes: 2 additions & 2 deletions src/poetry_plugin_dotenv/dotenv/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Literal:

value: str

def resolve(self, *args, **kwargs) -> str:
def resolve(self, *args, **kwargs) -> str: # type: ignore[no-untyped-def]
"""Get a literal value."""

return self.value
Expand All @@ -45,7 +45,7 @@ class Variable:
name: str
default: str | None = None

def resolve(self, env: OrderedDict[str, str], *args, **kwargs) -> str:
def resolve(self, env: OrderedDict[str, str], *args, **kwargs) -> str: # type: ignore[no-untyped-def]
"""Get a variable value."""

default = self.default if self.default else ""
Expand Down
2 changes: 1 addition & 1 deletion src/poetry_plugin_dotenv/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def activate(self, application: Application) -> None: # pragma: no cover

application.event_dispatcher.add_listener(COMMAND, listener=self.load) # type: ignore[union-attr, arg-type]

def load(self, event: ConsoleCommandEvent, *args, **kwargs) -> None:
def load(self, event: ConsoleCommandEvent, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
"""Load a dotenv file."""

logger = Logger(event)
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Iterator
from pathlib import Path


Expand Down Expand Up @@ -46,7 +46,7 @@ def remove(filepath: str) -> None:


@pytest.fixture()
def dotenv_file(tmp_path: Path) -> Generator:
def dotenv_file(tmp_path: Path) -> Iterator[str]:
"""Get a dotenv file."""

filepath = tmp_path / ".env"
Expand Down
2 changes: 1 addition & 1 deletion tests/dotenv/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import TYPE_CHECKING
from unittest import mock

import sh
import sh # type: ignore[import-untyped]
import pytest

from poetry_plugin_dotenv.dotenv import core as dotenv
Expand Down

0 comments on commit d28e69d

Please sign in to comment.