From c71a9bb94c8b5a649608695a7da39fb8bb353bd4 Mon Sep 17 00:00:00 2001 From: Joakim Soderlund Date: Sun, 18 Dec 2022 18:21:58 +0100 Subject: [PATCH] Explicitly declare optional parameters --- fimfarchive/converters/fpub_epub.py | 2 +- fimfarchive/fetchers/directory.py | 4 ++-- fimfarchive/mappers.py | 2 +- fimfarchive/stories.py | 8 ++++---- fimfarchive/tasks/build.py | 4 ++-- fimfarchive/tasks/update.py | 4 ++-- fimfarchive/utils.py | 6 +++++- tests/test_utils.py | 2 +- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fimfarchive/converters/fpub_epub.py b/fimfarchive/converters/fpub_epub.py index 3e78c85..4f00dcd 100644 --- a/fimfarchive/converters/fpub_epub.py +++ b/fimfarchive/converters/fpub_epub.py @@ -77,7 +77,7 @@ class FpubEpubConverter(Converter): Converts story data from FPUB to EPUB. """ - def __init__(self, logdir: Union[Path, str] = None) -> None: + def __init__(self, logdir: Union[None, Path, str] = None) -> None: self.logdir = get_path(logdir) if self.logdir and not self.logdir.is_dir(): diff --git a/fimfarchive/fetchers/directory.py b/fimfarchive/fetchers/directory.py index f21da27..24baf84 100644 --- a/fimfarchive/fetchers/directory.py +++ b/fimfarchive/fetchers/directory.py @@ -49,8 +49,8 @@ class DirectoryFetcher(Iterable[Story], Sized, Fetcher): def __init__( self, - meta_path: Union[Path, str] = None, - data_path: Union[Path, str] = None, + meta_path: Union[None, Path, str] = None, + data_path: Union[None, Path, str] = None, flavors: Iterable[Flavor] = tuple(), ) -> None: """ diff --git a/fimfarchive/mappers.py b/fimfarchive/mappers.py index eb4ab5b..3505c17 100644 --- a/fimfarchive/mappers.py +++ b/fimfarchive/mappers.py @@ -134,7 +134,7 @@ class StorySlugMapper(Mapper[str]): Returns a slug-based file path for a story. """ - def __init__(self, template: str = None) -> None: + def __init__(self, template: Optional[str] = None) -> None: """ Constructor. diff --git a/fimfarchive/stories.py b/fimfarchive/stories.py index 7d80b27..58c5bad 100644 --- a/fimfarchive/stories.py +++ b/fimfarchive/stories.py @@ -22,7 +22,7 @@ Stories for Fimfarchive. # -from typing import TYPE_CHECKING, Any, Dict, Iterable, TypeVar +from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, TypeVar from fimfarchive.exceptions import StorySourceError @@ -48,9 +48,9 @@ class Story: def __init__( self, key: int, - fetcher: Fetcher = None, - meta: Dict[str, Any] = None, - data: bytes = None, + fetcher: Optional[Fetcher] = None, + meta: Optional[Dict[str, Any]] = None, + data: Optional[bytes] = None, flavors: Iterable[Flavor] = (), ) -> None: """ diff --git a/fimfarchive/tasks/build.py b/fimfarchive/tasks/build.py index 5d09883..24392ae 100644 --- a/fimfarchive/tasks/build.py +++ b/fimfarchive/tasks/build.py @@ -52,8 +52,8 @@ class BuildTask: self, output: PathArg, upcoming: Iterable[Story], - previous: Fetcher = None, - extras: PathArg = None, + previous: Optional[Fetcher] = None, + extras: Optional[PathArg] = None, ) -> None: """ Constructor. diff --git a/fimfarchive/tasks/update.py b/fimfarchive/tasks/update.py index 62de2b4..33ebc87 100644 --- a/fimfarchive/tasks/update.py +++ b/fimfarchive/tasks/update.py @@ -76,8 +76,8 @@ class UpdateTask(SignalSender): self, fimfarchive: Fetcher, fimfiction: Fetcher, - selector: Selector = None, - stamper: Stamper = None, + selector: Optional[Selector] = None, + stamper: Optional[Stamper] = None, workdir: str = DEFAULT_WORKDIR, retries: int = DEFAULT_RETRIES, skips: int = DEFAULT_SKIPS, diff --git a/fimfarchive/utils.py b/fimfarchive/utils.py index 4d0aa1f..34b80af 100644 --- a/fimfarchive/utils.py +++ b/fimfarchive/utils.py @@ -281,7 +281,11 @@ class ResourceLoader: self.package = package self.binary = binary - def __call__(self, name: str, binary: bool = None) -> Union[str, bytes]: + def __call__( + self, + name: str, + binary: Optional[bool] = None, + ) -> Union[str, bytes]: """ Loads a package resource. diff --git a/tests/test_utils.py b/tests/test_utils.py index e571aa9..1937726 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -53,7 +53,7 @@ class TestEmpty: """ Tests `Empty` class evaluates to `False`. """ - assert not Empty + assert bool(Empty) is False def test_empty_class_is_empty(self): """