Skip to content

Commit 92c5986

Browse files
committed
Remove nominal typing via abc.ABC
1 parent 635df30 commit 92c5986

File tree

6 files changed

+44
-42
lines changed

6 files changed

+44
-42
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ target-version = "py310"
8181
strict = true
8282

8383
[tool.mypy]
84-
exclude = ["dist"]
84+
strict = true
8585

8686
[[tool.mypy.overrides]]
8787
module = ["ebooklib", "ebooklib.epub", "mobi", "kindle"]

src/screener/py.typed

Whitespace-only changes.

src/screener/reader/abstract.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/screener/reader/epub.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
11
from __future__ import annotations
22

3+
import typing
34
import warnings
4-
from typing import TYPE_CHECKING
55

6-
if TYPE_CHECKING:
6+
if typing.TYPE_CHECKING:
77
from pathlib import Path
8+
from types import TracebackType
89

910
from ebooklib import epub
1011

11-
from .abstract import AbstractReader
1212

13-
14-
class EpubFileReader(AbstractReader):
15-
def __init__(self: EpubFileReader, file_path: Path) -> None:
16-
super().__init__(file_path)
13+
class EpubFileReader:
14+
def __init__(self, file_path: Path) -> None:
15+
self.file_path = file_path
1716
self.book: epub.EpubBook
1817

19-
def __enter__(self: EpubFileReader) -> EpubFileReader:
18+
def __enter__(self) -> typing.Self:
2019
with warnings.catch_warnings():
2120
# Have to do this because of bug in ebooklib.
2221
warnings.simplefilter("ignore")
2322
self.book = epub.read_epub(self.file_path, options={"ignore_ncx": False})
2423
return self
24+
25+
@typing.overload
26+
def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None: ...
27+
28+
@typing.overload
29+
def __exit__(
30+
self,
31+
exc_type: type[BaseException],
32+
exc_val: BaseException,
33+
exc_tb: TracebackType,
34+
) -> None: ...
35+
36+
def __exit__(
37+
self,
38+
exc_type: type[BaseException] | None,
39+
exc_val: BaseException | None,
40+
exc_tb: TracebackType | None,
41+
) -> None: ...

src/screener/reader/kindle.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
from __future__ import annotations
22

33
import shutil
4-
from typing import TYPE_CHECKING
4+
import typing
55

6-
if TYPE_CHECKING:
6+
if typing.TYPE_CHECKING:
77
from pathlib import Path
88
from types import TracebackType
99

1010
from mobi import extract
1111

12-
from .abstract import AbstractReader
1312

14-
15-
class KindleFileReader(AbstractReader):
16-
def __init__(self: KindleFileReader, file_path: Path) -> None:
17-
super().__init__(file_path)
13+
class KindleFileReader:
14+
def __init__(self, file_path: Path) -> None:
15+
self.file_path = file_path
1816
self._temp_dir = None
1917
self.generated_translation = None
2018

21-
def __enter__(self: KindleFileReader) -> KindleFileReader:
19+
def __enter__(self) -> typing.Self:
2220
# The `mobi` library likes file paths as strings for whatever reason.
2321
self._temp_dir, self.generated_translation = extract(str(self.file_path))
2422
if self.generated_translation is None or self._temp_dir is None:
2523
msg = "Could not extract Kindle file"
2624
raise ValueError(msg)
2725
return self
2826

27+
@typing.overload
28+
def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None: ...
29+
30+
@typing.overload
31+
def __exit__(
32+
self,
33+
exc_type: type[BaseException],
34+
exc_val: BaseException,
35+
exc_tb: TracebackType,
36+
) -> None: ...
37+
2938
def __exit__(
30-
self: KindleFileReader,
39+
self,
3140
exc_type: type[BaseException] | None,
3241
exc_val: BaseException | None,
3342
exc_tb: TracebackType | None,

tests/test_parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Test the parser module; for use with `pytest`."""
2-
31
from __future__ import annotations
42

53
from pathlib import Path

0 commit comments

Comments
 (0)