Skip to content

Commit

Permalink
style: Add mypy type checks, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janw committed May 1, 2023
1 parent b7f8dba commit 4647755
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 16 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ jobs:
- name: Check out
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- name: Set up python environment
uses: actions/setup-python@v4
with:
cache: 'poetry'

- run: poetry install --no-root --with=dev --sync

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}

- uses: pre-commit/[email protected]
- run: poetry run pre-commit run --show-diff-on-failure --color=always --all-files
shell: bash
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ repos:
hooks:
- id: black

- repo: local
hooks:
- id: mypy
name: mypy
entry: poetry run mypy
require_serial: true
language: system
types: [python]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
Expand Down
3 changes: 2 additions & 1 deletion podcast_archiver/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from pydantic import types

if TYPE_CHECKING:
from pydantic import BaseSettings, ModelField
from pydantic import BaseSettings
from pydantic.fields import ModelField


class readable_file(argparse.Action):
Expand Down
10 changes: 5 additions & 5 deletions podcast_archiver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import textwrap
from pathlib import Path
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING, Any, Union

from pydantic import BaseSettings, DirectoryPath, Field, FilePath, validator
from yaml import safe_load
Expand Down Expand Up @@ -95,13 +95,13 @@ class Config:
)

@validator("archive_directory", pre=True)
def normalize_archive_directory(cls, v):
def normalize_archive_directory(cls, v) -> Path:
if v is None:
return Path.cwd()
return Path(v).expanduser()

@validator("opml_files", pre=True, each_item=True)
def normalize_opml_files(cls, v):
def normalize_opml_files(cls, v: Any) -> Path:
return Path(v).expanduser()

@classmethod
Expand All @@ -111,7 +111,7 @@ def load_from_yaml(cls, path: Union[Path, None]) -> Settings:
content = safe_load(filep)
if content:
return cls.parse_obj(content)
return cls()
return cls() # type: ignore[call-arg]

@classmethod
def load_and_merge(cls, path: Union[Path, None], args: argparse.Namespace):
Expand All @@ -132,7 +132,7 @@ def load_and_merge(cls, path: Union[Path, None], args: argparse.Namespace):
return cls.parse_obj(merged_settings)

@classmethod
def generate_example(cls, path: Path) -> str:
def generate_example(cls, path: Path) -> None:
text = ["## Configuration for podcast-archiver"]
text.append(f"## Generated with version {__version__}\n")
for name, field in cls.__fields__.items():
Expand Down
227 changes: 226 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4647755

Please sign in to comment.