Skip to content

Commit dc57e64

Browse files
committed
fixup! Fix all type hints, qa and typing issues
1 parent 63bc653 commit dc57e64

File tree

7 files changed

+10
-9
lines changed

7 files changed

+10
-9
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add utility function to compute ZIM Tags #164, including deduplication #156
13+
- Expose new `optimization.get_optimization_method` to get the proper optimization method to call for a given image format
1314

1415
## Changed
1516
- **BREAKING** Renamed `zimscraperlib.image.convertion` to `zimscraperlib.image.conversion` to fix typo
1617
- **BREAKING** Many changes in type hints to match the real underlying code
1718
- **BREAKING** Force all boolean arguments (and some other non-obvious parameters) to be keyword-only in function calls for clarity / disambiguation (see ruff rule FBT002)
1819
- Prefer to use `IO[bytes]` to `io.BytesIO` when possible since it is more generic
20+
- **BREAKING** `i18n.NotFound` renamed `i18n.NotFoundError`
1921

2022
### Fixed
2123

Diff for: src/zimscraperlib/image/optimization.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import os
3030
import pathlib
3131
import subprocess
32+
from typing import Callable
3233

3334
import piexif
3435
from optimize_images.img_aux_processing import do_reduce_colors, rebuild_palette
@@ -311,7 +312,7 @@ def optimize_image(
311312
src.unlink()
312313

313314

314-
def get_optimization_method(fmt: str):
315+
def get_optimization_method(fmt: str) -> Callable:
315316
"""Return the proper optimization method to call for a given image format"""
316317

317318
def raise_error(*_, orig_format):

Diff for: src/zimscraperlib/image/probing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def solarize(r: int, g: int, b: int) -> tuple[int, int, int]:
4949

5050
def is_hex_color(text: str) -> bool:
5151
"""whether supplied text is a valid hex-formated color code"""
52-
return re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", text) is not None
52+
return bool(re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", text))
5353

5454

5555
def format_for(

Diff for: src/zimscraperlib/image/transformation.py

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def resize_image(
6161
src.seek(0)
6262

6363
if image_format is None: # pragma: no cover
64-
# not covered by test, no idea how to generate an image without a format
65-
# returned by PIL
6664
raise ValueError("Impossible to guess format from src image")
6765

6866
save_image(

Diff for: src/zimscraperlib/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
def get_mime_for_name(
4040
filename: str | pathlib.Path,
4141
fallback: str | None = FALLBACK_MIME,
42-
no_ext_to=ARTICLE_MIME,
42+
no_ext_to: str | None = ARTICLE_MIME,
4343
) -> str | None:
4444
"""MIME-Type string from a filename
4545

Diff for: src/zimscraperlib/zim/creator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def mimetype_for(
8686
or mimetype.startswith("text/")
8787
):
8888
mimetype = get_mime_for_name(
89-
fpath if fpath else path, mimetype, mimetype # pyright: ignore
89+
filename=fpath if fpath else path, fallback=mimetype, no_ext_to=mimetype
9090
)
9191
return mimetype
9292

Diff for: src/zimscraperlib/zim/filesystem.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ def add_redirects_to_zim(
105105
if redirects_file:
106106
with open(redirects_file) as fh:
107107
for linenumber, line in enumerate(fh.readlines()):
108-
matchs = re.match(r"^(.)\t(.+)\t(.*)\t(.+)$", line)
109-
if not matchs:
108+
match = re.match(r"^(.)\t(.+)\t(.*)\t(.+)$", line)
109+
if not match:
110110
logger.warning(
111111
f"Redirects file: line {linenumber} does not match expected "
112112
f"regexp: {line}"
113113
)
114114
continue
115-
namespace, path, title, target_url = matchs.groups()
115+
namespace, path, title, target_url = match.groups()
116116
if namespace.strip():
117117
path = f"{namespace.strip()}/{path}"
118118
zim_file.add_redirect(path, target_url, title)

0 commit comments

Comments
 (0)