Skip to content

Commit 91f1100

Browse files
committed
Fix linting and type checking issues following black, ruff and pyright update
1 parent 1242168 commit 91f1100

21 files changed

Lines changed: 124 additions & 104 deletions

src/zimscraperlib/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
""" Files manipulation tools
1+
"""Files manipulation tools
22
3-
Shortcuts to retrieve mime type using magic"""
3+
Shortcuts to retrieve mime type using magic"""
44

55
import pathlib
66
from contextlib import contextmanager

src/zimscraperlib/fix_ogvjs_dist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" quick script to fix videojs-ogvjs so that it triggers on webm mimetype """
1+
"""quick script to fix videojs-ogvjs so that it triggers on webm mimetype"""
22

33
import logging
44
import pathlib

src/zimscraperlib/html.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Tools to work with HTML contents """
1+
"""Tools to work with HTML contents"""
22

33
import pathlib
44
from typing import BinaryIO, TextIO
@@ -43,11 +43,13 @@ def find_language_in(content: str | BinaryIO | TextIO, mime_type: str) -> str:
4343
continue
4444
if (
4545
nodename == "meta"
46-
and not node.attrs.get("http-equiv", "").lower()
46+
and not node.attrs.get(
47+
"http-equiv", ""
48+
).lower() # pyright:ignore[reportUnknownMemberType, reportAttributeAccessIssue]
4749
== "content-language"
4850
):
4951
continue
50-
return node.attrs[key]
52+
return node.attrs[key] # pyright:ignore[reportReturnType]
5153
return ""
5254

5355

src/zimscraperlib/image/optimization.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
""" An image optimization module to optimize the following image formats:
1+
"""An image optimization module to optimize the following image formats:
22
3-
- JPEG (using optimize-images)
4-
- PNG (using optimize-images)
5-
- GIF (using gifsicle with lossy optimization)
6-
- WebP (using Pillow)
3+
- JPEG (using optimize-images)
4+
- PNG (using optimize-images)
5+
- GIF (using gifsicle with lossy optimization)
6+
- WebP (using Pillow)
77
8-
Some important notes:
9-
- This makes use of the --lossy option from gifsicle which is present
10-
only in versions above 1.92.
11-
If the package manager has a lower version, you can build gifsicle
12-
from source and install or
13-
do not use the lossiness option.
8+
Some important notes:
9+
- This makes use of the --lossy option from gifsicle which is present
10+
only in versions above 1.92.
11+
If the package manager has a lower version, you can build gifsicle
12+
from source and install or
13+
do not use the lossiness option.
1414
15-
- Presets for the optimizer are available in zimscraperlib.image.presets.
15+
- Presets for the optimizer are available in zimscraperlib.image.presets.
1616
17-
- If no options for an image optimization is passed, the optimizer
18-
can still run on default settings which give
19-
a bit less size than the original images but maintain a high quality. """
17+
- If no options for an image optimization is passed, the optimizer
18+
can still run on default settings which give
19+
a bit less size than the original images but maintain a high quality."""
2020

2121
import io
2222
import os

src/zimscraperlib/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Miscelaneous utils"""
1+
"""Miscelaneous utils"""
22

33
from typing import TypeVar
44

src/zimscraperlib/rewriting/css.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" CSS Rewriting
1+
"""CSS Rewriting
22
33
This modules contains tools to rewrite CSS retrieved from an online source so that it
44
can safely operate within a ZIM, linking only to ZIM entries everytime a URL is used.

src/zimscraperlib/rewriting/html.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" HTML Rewriting
1+
"""HTML Rewriting
22
33
This modules contains tools to rewrite HTML retrieved from an online source so that it
44
can safely operate within a ZIM.
@@ -101,8 +101,12 @@ def extract_base_href(content: str) -> str | None:
101101
if not soup.head:
102102
return None
103103
for base in soup.head.find_all("base"):
104-
if base.has_attr("href"):
105-
return base["href"]
104+
if base.has_attr( # pyright:ignore[reportUnknownMemberType, reportAttributeAccessIssue]
105+
"href"
106+
):
107+
return base[ # pyright:ignore[reportIndexIssue, reportUnknownVariableType, reportArgumentType, reportReturnType]
108+
"href"
109+
]
106110
return None
107111

108112

src/zimscraperlib/rewriting/js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" JS Rewriting
1+
"""JS Rewriting
22
33
This modules contains tools to rewrite JS retrieved from an online source so that it
44
can safely operate within a ZIM. It is based on the assumption that wombat.js will be

src/zimscraperlib/rewriting/url_rewriting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" URL rewriting tools
1+
"""URL rewriting tools
22
33
This module is about url and entry path rewriting.
44

src/zimscraperlib/types.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
""" File extensions to MIME-Type mapping
1+
"""File extensions to MIME-Type mapping
22
3-
All libzim *articles* contains the mime-type of their content, for the libzim
4-
reader to properly return it.
3+
All libzim *articles* contains the mime-type of their content, for the libzim
4+
reader to properly return it.
55
6-
Providing accurate mime-type for ZIM Article is important to prevent broken features
7-
upon reading.
8-
Ex.: youtube scraper uses Web Assembly files (.wasm) for the WebM codecs.
9-
Without the proper mime-type, wasm files are returned as octet-stream and thus
10-
not loaded efficiently.
6+
Providing accurate mime-type for ZIM Article is important to prevent broken features
7+
upon reading.
8+
Ex.: youtube scraper uses Web Assembly files (.wasm) for the WebM codecs.
9+
Without the proper mime-type, wasm files are returned as octet-stream and thus
10+
not loaded efficiently.
1111
12-
Should your scraper need additional mapping, use mimetypes.add_type() and it will
13-
be automatically used. """
12+
Should your scraper need additional mapping, use mimetypes.add_type() and it will
13+
be automatically used."""
1414

1515
import mimetypes
1616
import pathlib

0 commit comments

Comments
 (0)