Skip to content

Commit 6f93ffe

Browse files
rgaudinbenoit74
authored andcommitted
Removed generyc pyright: ignore statements
We should really ban wide `pyright: ignore` statements and use specifix expections wherever necessary (or comply!) This fixes it in the current codebase
1 parent cee04d5 commit 6f93ffe

15 files changed

+33
-37
lines changed

src/zimscraperlib/rewriting/css.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -186,29 +186,27 @@ def _process_node(self, node: ast.Node):
186186
)
187187
elif isinstance(node, ast.FunctionBlock):
188188
if node.lower_name == "url": # pyright: ignore[reportUnknownMemberType]
189-
url_node: ast.Node = node.arguments[0] # pyright: ignore
189+
url_node: ast.Node = node.arguments[0]
190190
new_url = self.url_rewriter(
191-
url_node.value, # pyright: ignore
191+
getattr(url_node, "value", ""),
192192
self.base_href,
193193
).rewriten_url
194-
url_node.value = str(new_url) # pyright: ignore
195-
url_node.representation = ( # pyright: ignore
196-
f'"{serialize_url(str(new_url))}"'
194+
setattr(url_node, "value", str(new_url)) # noqa: B010
195+
setattr( # noqa: B010
196+
url_node, "representation", f'"{serialize_url(str(new_url))}"'
197197
)
198198

199199
else:
200200
self._process_list(
201-
node.arguments, # pyright: ignore
201+
getattr(node, "arguments", []),
202202
)
203203
elif isinstance(node, ast.AtRule):
204-
self._process_list(node.prelude) # pyright: ignore
205-
self._process_list(node.content) # pyright: ignore
204+
self._process_list(node.prelude)
205+
self._process_list(node.content)
206206
elif isinstance(node, ast.Declaration):
207-
self._process_list(node.value) # pyright: ignore
207+
self._process_list(node.value)
208208
elif isinstance(node, ast.URLToken):
209-
new_url = self.url_rewriter(
210-
node.value, self.base_href
211-
).rewriten_url # pyright: ignore
209+
new_url = self.url_rewriter(node.value, self.base_href).rewriten_url
212210
node.value = new_url
213211
node.representation = f"url({serialize_url(new_url)})"
214212

src/zimscraperlib/video/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def buffersize(self, value):
116116
@property
117117
def video_scale(self):
118118
# remove "scale='" and "'" and return the value in between
119-
return self.get("-vf")[7:-1] if self.get("-vf") else None # pyright: ignore
119+
return self.get("-vf", [])[7:-1] if self.get("-vf") else None
120120

121121
@video_scale.setter
122122
def video_scale(self, value):

src/zimscraperlib/zim/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
zim.items: item to add to creator
1010
zim.archive: read ZIM files, accessing or searching its content"""
1111

12-
from beartype.claw import beartype_this_package
13-
from libzim.writer import Blob # pyright: ignore
14-
15-
beartype_this_package()
12+
from libzim.writer import Blob # pyright: ignore[reportMissingModuleSource]
1613

1714
from zimscraperlib.zim.archive import Archive
1815
from zimscraperlib.zim.creator import Creator

src/zimscraperlib/zim/archive.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
from collections.abc import Iterable
1515

16-
import libzim.reader # pyright: ignore
17-
import libzim.search # Query, Searcher # pyright: ignore
18-
import libzim.suggestion # SuggestionSearcher # pyright: ignore
16+
import libzim.reader # pyright: ignore[reportMissingModuleSource]
17+
import libzim.search # pyright: ignore[reportMissingModuleSource]
18+
import libzim.suggestion # pyright: ignore[reportMissingModuleSource]
1919

2020
from zimscraperlib.zim._libkiwix import CounterMap, convertTags, parseMimetypeCounter
2121

src/zimscraperlib/zim/creator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import re
2626
import weakref
2727

28-
import libzim.writer # pyright: ignore
28+
import libzim.writer # pyright: ignore[reportMissingModuleSource]
2929
import PIL.Image
3030

3131
from zimscraperlib import logger

src/zimscraperlib/zim/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io
66
import pathlib
77

8-
import libzim.writer # pyright: ignore
8+
import libzim.writer # pyright: ignore[reportMissingModuleSource]
99

1010
try:
1111
import pymupdf

src/zimscraperlib/zim/items.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections.abc import Callable
1414
from typing import Any
1515

16-
import libzim.writer # pyright: ignore
16+
import libzim.writer # pyright: ignore[reportMissingModuleSource]
1717

1818
from zimscraperlib.download import stream_file
1919
from zimscraperlib.filesystem import get_content_mimetype, get_file_mimetype

src/zimscraperlib/zim/providers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import pathlib
1616
from collections.abc import Generator
1717

18-
import libzim.writer # pyright: ignore
18+
import libzim.writer # pyright: ignore[reportMissingModuleSource]
1919
import requests
2020

2121
from zimscraperlib.download import _get_retry_adapter, stream_file
@@ -60,7 +60,7 @@ def __init__(
6060
self.fileobj.seek(0, io.SEEK_SET)
6161

6262
def get_size(self) -> int:
63-
return self.size # pyright: ignore
63+
return getattr(self, "size", -1)
6464

6565
def gen_blob(self) -> Generator[libzim.writer.Blob, None, None]:
6666
yield libzim.writer.Blob(self.fileobj.getvalue()) # pragma: no cover
@@ -91,7 +91,7 @@ def get_size_of(url) -> int | None:
9191
return None
9292

9393
def get_size(self) -> int:
94-
return self.size # pyright: ignore
94+
return getattr(self, "size", -1)
9595

9696
def gen_blob(self) -> Generator[libzim.writer.Blob, None, None]: # pragma: no cover
9797
for chunk in self.resp.iter_content(10 * 1024):

tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33

44
from invoke.context import Context
5-
from invoke.tasks import task # pyright: ignore [reportUnknownVariableType]
5+
from invoke.tasks import task # pyright: ignore[reportUnknownVariableType]
66

77
use_pty = not os.getenv("CI", "")
88

tests/download/test_download.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_first_block_download_custom_session(mocker, valid_http_url):
118118
headers=None,
119119
timeout=DEFAULT_WEB_REQUESTS_TIMEOUT,
120120
)
121-
requests.Session.assert_not_called() # pyright: ignore
121+
requests.Session.assert_not_called() # pyright: ignore[reportAttributeAccessIssue]
122122

123123

124124
@pytest.mark.slow
@@ -226,12 +226,13 @@ def test_youtube_download_nowait(tmp_path):
226226
BestMp4.get_options(target_dir=tmp_path),
227227
wait=False,
228228
)
229-
assert future.running() # pyright: ignore
229+
assert future.running() # pyright: ignore[reportAttributeAccessIssue]
230230
assert not yt_downloader.executor._shutdown
231231
done, not_done = concurrent.futures.wait(
232-
[future], return_when=concurrent.futures.ALL_COMPLETED # pyright: ignore
232+
[future], # pyright: ignore[reportArgumentType]
233+
return_when=concurrent.futures.ALL_COMPLETED,
233234
)
234-
assert future.exception() is None # pyright: ignore
235+
assert future.exception() is None # pyright: ignore[reportAttributeAccessIssue]
235236
assert len(done) == 1
236237
assert len(not_done) == 0
237238

tests/types/test_types.py

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def test_constants():
1818
[
1919
("hello.html", "text/html", None, None),
2020
("some picture.png", "image/png", None, None),
21-
# make sure we get default fallback on error
22-
(b"-", "application/octet-stream", None, None),
2321
# make sure fallback is not returned on success
2422
("hello.html", "text/html", "text/plain", None),
2523
# make sure fallback is returned on missing

tests/video/test_video.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def test_config_build_from():
8484
assert idx != -1
8585
assert args[idx + 1] == str(getattr(config, attr))
8686
video_scale = config.video_scale
87-
qmin, qmax = config.quantizer_scale_range # pyright: ignore
87+
qmin, qmax = (
88+
config.quantizer_scale_range # pyright: ignore[reportGeneralTypeIssues]
89+
)
8890
assert args.index("-qmin") != -1 and args[args.index("-qmin") + 1] == str(qmin)
8991
assert args.index("-qmax") != -1 and args[args.index("-qmax") + 1] == str(qmax)
9092
assert (

tests/zim/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import pathlib
33

4-
import libzim.writer # pyright: ignore
4+
import libzim.writer # pyright: ignore[reportMissingModuleSource]
55
import pytest
66

77
from zimscraperlib.zim import Archive, Creator

tests/zim/test_metadata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_validate_tags_invalid(
118118
value: list[str] | str | int, exception: type, error: str
119119
):
120120
with pytest.raises(exception, match=re.escape(error)):
121-
metadata.TagsMetadata(value) # pyright: ignore [reportArgumentType]
121+
metadata.TagsMetadata(value) # pyright: ignore[reportArgumentType]
122122

123123

124124
def test_validate_dedup_tags():

tests/zim/test_zim_creator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from unittest.mock import call, patch
1818

1919
import pytest
20-
from libzim.writer import Compression # pyright: ignore
20+
from libzim.writer import Compression # pyright: ignore[reportMissingModuleSource]
2121

2222
from zimscraperlib.constants import UTF8
2323
from zimscraperlib.download import save_large_file, stream_file

0 commit comments

Comments
 (0)