Skip to content

Commit

Permalink
Inherit from abc.ABC
Browse files Browse the repository at this point in the history
If we're doing nominal typing, do it correctly.
  • Loading branch information
tjkuson committed Sep 28, 2024
1 parent 635df30 commit 85e9f26
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ target-version = "py310"
strict = true

[tool.mypy]
exclude = ["dist"]
strict = true

[[tool.mypy.overrides]]
module = ["ebooklib", "ebooklib.epub", "mobi", "kindle"]
Expand Down
Empty file added src/screener/py.typed
Empty file.
22 changes: 0 additions & 22 deletions src/screener/reader/abstract.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/screener/reader/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ebooklib import epub

from .abstract import AbstractReader
from screener.reader.types import AbstractReader


class EpubFileReader(AbstractReader):
Expand Down
2 changes: 1 addition & 1 deletion src/screener/reader/kindle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from mobi import extract

from .abstract import AbstractReader
from screener.reader.types import AbstractReader


class KindleFileReader(AbstractReader):
Expand Down
35 changes: 35 additions & 0 deletions src/screener/reader/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

import abc
import typing

if typing.TYPE_CHECKING:
from pathlib import Path
from types import TracebackType


class AbstractReader(abc.ABC):
def __init__(self: AbstractReader, file_path: Path) -> None:
self.file_path = file_path

@abc.abstractmethod
def __enter__(self: AbstractReader) -> AbstractReader: ...

@typing.overload
def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None: ...

@typing.overload
def __exit__(
self,
exc_type: type[BaseException],
exc_val: BaseException,
exc_tb: TracebackType,
) -> None: ...

@abc.abstractmethod
def __exit__(
self: AbstractReader,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None: ...

0 comments on commit 85e9f26

Please sign in to comment.