Skip to content

Commit

Permalink
add some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Jan 4, 2024
1 parent 3b467bd commit 0f5bd49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion organize/cli.py
Expand Up @@ -52,7 +52,7 @@

from organize import Config, ConfigError
from organize.find_config import ConfigNotFound, find_config, list_configs
from organize.output import JSONL, Default
from organize.output import JSONL, Default, Output

from .__version__ import __is_prerelease__, __version__

Expand Down Expand Up @@ -93,6 +93,7 @@ def execute(
simulate: bool,
) -> None:
output = JSONL() if format == "jsonl" else Default()
assert isinstance(output, Output)
config_path = find_config(name_or_path=config)
Config.from_path(config_path).execute(
simulate=simulate,
Expand Down
6 changes: 3 additions & 3 deletions organize/config.py
Expand Up @@ -59,7 +59,7 @@ class Config:
_config_path: Optional[Path] = None

@classmethod
def from_string(cls, config: str, config_path: Optional[Path] = None):
def from_string(cls, config: str, config_path: Optional[Path] = None) -> "Config":
dedented = textwrap.dedent(config)
as_dict = yaml.load(dedented, Loader=yaml.SafeLoader)
try:
Expand All @@ -71,7 +71,7 @@ def from_string(cls, config: str, config_path: Optional[Path] = None):
raise ConfigError(e=e, config_path=config_path) from e

@classmethod
def from_path(cls, config_path: Path):
def from_path(cls, config_path: Path) -> "Config":
text = config_path.read_text(encoding="utf-8")
inst = cls.from_string(text, config_path=config_path)
return inst
Expand All @@ -83,7 +83,7 @@ def execute(
tags: Tags = set(),
skip_tags: Tags = set(),
working_dir: Union[str, Path] = ".",
):
) -> None:
working_path = Path(render(str(working_dir)))
os.chdir(working_path)
output.start(
Expand Down
5 changes: 3 additions & 2 deletions organize/output/output.py
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Literal, Optional, Protocol
from typing import TYPE_CHECKING, Literal, Optional, Protocol, runtime_checkable

if TYPE_CHECKING:
from pathlib import Path
Expand All @@ -13,6 +13,7 @@
Level = Literal["info", "warn", "error"]


@runtime_checkable
class Output(Protocol):
"""
The protocol all of organize's outputs must adhere to.
Expand Down Expand Up @@ -44,5 +45,5 @@ def confirm(
) -> bool:
...

def end(self, success_count: int, error_count: int):
def end(self, success_count: int, error_count: int) -> None:
...

0 comments on commit 0f5bd49

Please sign in to comment.