Skip to content

Commit e4a83dd

Browse files
committed
Fix StaticItem typing issue + remove reference to callback removed long ago
1 parent 64b66c8 commit e4a83dd

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

src/zimscraperlib/zim/filesystem.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def __init__(
4646
self,
4747
root: pathlib.Path,
4848
filepath: pathlib.Path,
49-
): # pyright: ignore
50-
super().__init__(root=root, filepath=filepath) # pyright: ignore
49+
):
50+
super().__init__(root=root, filepath=filepath)
5151
# first look inside the file's magic headers
5252
self.mimetype = get_file_mimetype(self.filepath)
5353
# most web-specific files are plain text. In this case, use extension

src/zimscraperlib/zim/items.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
import tempfile
1111
import urllib.parse
12-
from typing import Dict, Union
12+
from typing import Any
1313

1414
import libzim.writer # pyright: ignore
1515

@@ -23,11 +23,9 @@
2323

2424

2525
class Item(libzim.writer.Item):
26-
"""libzim.writer.Item returning props for path/title/mimetype plus a callback
26+
"""libzim.writer.Item returning props for path/title/mimetype"""
2727

28-
Calls your `callback` prop on deletion"""
29-
30-
def __init__(self, **kwargs: Dict[str, Union[str, bool, bytes]]):
28+
def __init__(self, **kwargs: Any):
3129
super().__init__()
3230
for k, v in kwargs.items():
3331
setattr(self, k, v)
@@ -106,7 +104,7 @@ def download_for_size(url, on_disk, tmp_dir=None):
106104
size, _ = stream_file(url.geturl(), fpath=fpath, byte_stream=stream)
107105
return fpath or stream, size
108106

109-
def __init__(self, url: str, **kwargs):
107+
def __init__(self, url: str, **kwargs: Any):
110108
super().__init__(**kwargs)
111109
self.url = urllib.parse.urlparse(url)
112110
use_disk = getattr(self, "use_disk", False)

tests/zim/test_zim_creator.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import base64
55
import datetime
66
import io
7-
import os
87
import pathlib
98
import random
109
import shutil
@@ -119,7 +118,7 @@ def test_noindexlanguage(tmp_path):
119118
creator = Creator(fpath, "welcome").config_dev_metadata(Language="bam")
120119
creator.config_indexing(False)
121120
with creator as creator:
122-
creator.add_item(StaticItem(path="welcome", content="hello")) # pyright: ignore
121+
creator.add_item(StaticItem(path="welcome", content="hello"))
123122
creator.add_item_for("index", "Index", content="-", mimetype="text/html")
124123

125124
reader = Archive(fpath)
@@ -165,15 +164,11 @@ def test_add_item_for_delete_fail(tmp_path, png_image):
165164
# copy file to local path
166165
shutil.copyfile(png_image, local_path)
167166

168-
def remove_source(item):
169-
os.remove(item.filepath)
170-
171167
with Creator(fpath, "welcome").config_dev_metadata() as creator:
172168
creator.add_item(
173169
StaticItem(
174-
filepath=local_path, # pyright: ignore
175-
path="index", # pyright: ignore
176-
callback=remove_source, # pyright: ignore
170+
filepath=local_path,
171+
path="index",
177172
),
178173
callback=(delete_callback, local_path),
179174
)
@@ -188,18 +183,18 @@ def test_compression(tmp_path):
188183
with Creator(
189184
tmp_path / "test.zim", "welcome", compression="zstd"
190185
).config_dev_metadata() as creator:
191-
creator.add_item(StaticItem(path="welcome", content="hello")) # pyright: ignore
186+
creator.add_item(StaticItem(path="welcome", content="hello"))
192187

193188
with Creator(
194189
fpath, "welcome", compression=Compression.zstd # pyright: ignore
195190
).config_dev_metadata() as creator:
196-
creator.add_item(StaticItem(path="welcome", content="hello")) # pyright: ignore
191+
creator.add_item(StaticItem(path="welcome", content="hello"))
197192

198193

199194
def test_double_finish(tmp_path):
200195
fpath = tmp_path / "test.zim"
201196
with Creator(fpath, "welcome").config_dev_metadata() as creator:
202-
creator.add_item(StaticItem(path="welcome", content="hello")) # pyright: ignore
197+
creator.add_item(StaticItem(path="welcome", content="hello"))
203198

204199
# ensure we can finish an already finished creator
205200
creator.finish()
@@ -219,11 +214,7 @@ def test_sourcefile_removal(tmp_path, html_file):
219214
# copy html to folder
220215
src_path = pathlib.Path(tmpdir.name, "source.html")
221216
shutil.copyfile(html_file, src_path)
222-
creator.add_item(
223-
StaticItem(
224-
filepath=src_path, path=src_path.name, ref=tmpdir # pyright: ignore
225-
)
226-
)
217+
creator.add_item(StaticItem(filepath=src_path, path=src_path.name, ref=tmpdir))
227218
del tmpdir
228219

229220
assert not src_path.exists()
@@ -241,7 +232,7 @@ def test_sourcefile_removal_std(tmp_path, html_file):
241232
StaticItem(
242233
filepath=paths[-1],
243234
path=paths[-1].name,
244-
mimetype="text/html", # pyright: ignore
235+
mimetype="text/html",
245236
),
246237
callback=(delete_callback, paths[-1]),
247238
)

0 commit comments

Comments
 (0)