Skip to content

Commit f633e7a

Browse files
rgaudinbenoit74
authored andcommitted
Fixing CounterMap type
1 parent 968a62c commit f633e7a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/zimscraperlib/zim/_libkiwix.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
from __future__ import annotations
1616

1717
import io
18-
from collections import namedtuple
18+
from typing import NamedTuple
1919

20-
MimetypeAndCounter = namedtuple("MimetypeAndCounter", ["mimetype", "value"])
21-
CounterMap = dict[
22-
type(MimetypeAndCounter.mimetype), type(MimetypeAndCounter.value) # pyright: ignore
23-
]
20+
21+
class MimetypeAndCounter(NamedTuple):
22+
mimetype: str
23+
value: int
24+
25+
26+
type CounterMap = dict[str, int]
2427

2528

2629
def getline(src: io.StringIO, delim: str | None = None) -> tuple[bool, str]:

src/zimscraperlib/zim/archive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import libzim.search # Query, Searcher # pyright: ignore
1818
import libzim.suggestion # SuggestionSearcher # pyright: ignore
1919

20-
from zimscraperlib.zim._libkiwix import convertTags, parseMimetypeCounter
20+
from zimscraperlib.zim._libkiwix import CounterMap, convertTags, parseMimetypeCounter
2121

2222

2323
class Archive(libzim.reader.Archive):
@@ -101,7 +101,7 @@ def get_search_results_count(self, query: str) -> int:
101101
return search.getEstimatedMatches()
102102

103103
@property
104-
def counters(self) -> dict[str, int]:
104+
def counters(self) -> CounterMap:
105105
try:
106106
return parseMimetypeCounter(self.get_text_metadata("Counter"))
107107
except RuntimeError: # pragma: no cover (no ZIM avail to test itl)

0 commit comments

Comments
 (0)