Skip to content

Commit dd2b6cf

Browse files
committed
plugins: replace Glossary type annotation with new limited types
- `ReaderGlossaryType` for `Reader` classes - `WriterGlossaryType` for `Writer` classes
1 parent 8a9e8fe commit dd2b6cf

File tree

62 files changed

+205
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+205
-124
lines changed

pyglossary/glossary_types.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"GlossaryExtendedType",
2727
"GlossaryType",
2828
"RawEntryType",
29+
"ReaderGlossaryType",
30+
"WriterGlossaryType",
2931
]
3032

3133
MultiStr: TypeAlias = "str | list[str]"
@@ -249,3 +251,81 @@ def progressbar(self) -> bool: ...
249251

250252
@progressbar.setter
251253
def progressbar(self, enabled: bool) -> None: ...
254+
255+
256+
class GlossaryInfoCommonType(typing.Protocol):
257+
def getInfo(self, key: str) -> str: ...
258+
259+
def setInfo(self, key: str, value: str) -> None: ...
260+
261+
@property
262+
def sourceLang(self) -> Lang | None: ...
263+
264+
@property
265+
def targetLang(self) -> Lang | None: ...
266+
267+
@property
268+
def sourceLangName(self) -> str: ...
269+
270+
@sourceLangName.setter
271+
def sourceLangName(self, langName: str) -> None: ...
272+
273+
@property
274+
def targetLangName(self) -> str: ...
275+
276+
@targetLangName.setter
277+
def targetLangName(self, langName: str) -> None: ...
278+
279+
@property
280+
def author(self) -> str: ...
281+
282+
283+
class ReaderGlossaryType(GlossaryInfoCommonType):
284+
def newEntry(
285+
self,
286+
word: MultiStr,
287+
defi: str,
288+
defiFormat: str = "",
289+
byteProgress: tuple[int, int] | None = None,
290+
) -> EntryType: ...
291+
292+
def newDataEntry(self, fname: str, data: bytes) -> EntryType: ...
293+
294+
@property
295+
def progressbar(self) -> bool: ...
296+
297+
def setDefaultDefiFormat(self, defiFormat: str) -> None: ...
298+
299+
def titleTag(self, sample: str) -> str: ...
300+
301+
302+
class WriterGlossaryType(GlossaryInfoCommonType):
303+
def collectDefiFormat(
304+
self,
305+
maxCount: int,
306+
) -> dict[str, float] | None: ...
307+
308+
def iterInfo(self) -> Iterator[tuple[str, str]]: ...
309+
310+
def getExtraInfos(self, excludeKeys: list[str]) -> dict[str, str]: ...
311+
312+
def wordTitleStr(
313+
self,
314+
word: str,
315+
sample: str = "",
316+
class_: str = "",
317+
) -> str: ...
318+
319+
@property
320+
def tmpDataDir(self) -> str: ...
321+
322+
def stripFullHtml(
323+
self,
324+
errorHandler: Callable[[EntryType, str], None] | None = None,
325+
) -> None: ...
326+
327+
def preventDuplicateWords(self) -> None: ...
328+
329+
def mergeEntriesWithSameHeadwordPlaintext(self) -> None: ...
330+
331+
def removeHtmlTagsAll(self) -> None: ...

pyglossary/plugins/aard2_slob/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections.abc import Iterator
99

1010
from pyglossary import slob
11-
from pyglossary.glossary_types import EntryType, GlossaryType
11+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
1212

1313
from pyglossary.core import exc_note, log, pip
1414
from pyglossary.plugins.aard2_slob.tags import (
@@ -29,7 +29,7 @@ class Reader:
2929
"icu": "PyICU", # >=1.5
3030
}
3131

32-
def __init__(self, glos: GlossaryType) -> None:
32+
def __init__(self, glos: ReaderGlossaryType) -> None:
3333
self._glos = glos
3434
self._clear()
3535
self._re_bword = re.compile(

pyglossary/plugins/aard2_slob/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Generator
1212

1313
from pyglossary import slob
14-
from pyglossary.glossary_types import EntryType, GlossaryType
14+
from pyglossary.glossary_types import EntryType, WriterGlossaryType
1515

1616
from pyglossary.core import cacheDir, exc_note, log, pip
1717
from pyglossary.plugins.aard2_slob.tags import (
@@ -65,7 +65,7 @@ class Writer:
6565
"mp4": "video/mp4",
6666
}
6767

68-
def __init__(self, glos: GlossaryType) -> None:
68+
def __init__(self, glos: WriterGlossaryType) -> None:
6969
self._glos = glos
7070
self._filename = ""
7171
self._resPrefix = ""

pyglossary/plugins/almaany/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import sqlite3
99
from collections.abc import Iterator
1010

11-
from pyglossary.glossary_types import EntryType, GlossaryType
11+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
1212

1313

1414
class Reader:
15-
def __init__(self, glos: GlossaryType) -> None:
15+
def __init__(self, glos: ReaderGlossaryType) -> None:
1616
self._glos = glos
1717
self._clear()
1818

pyglossary/plugins/appledict/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import io
4343
from collections.abc import Generator
4444

45-
from pyglossary.glossary_types import EntryType, GlossaryType
45+
from pyglossary.glossary_types import EntryType, WriterGlossaryType
4646

4747

4848
sys.setrecursionlimit(10000)
@@ -182,7 +182,7 @@ class Writer:
182182
_jing: bool = False
183183
_indexes: str = "" # FIXME: rename to indexes_lang?
184184

185-
def __init__(self, glos: GlossaryType) -> None:
185+
def __init__(self, glos: WriterGlossaryType) -> None:
186186
self._glos = glos
187187
self._dirname = ""
188188

pyglossary/plugins/appledict_bin/reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
HtmlProcessingInstruction,
5252
)
5353

54-
from pyglossary.glossary_types import EntryType, GlossaryType
54+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
5555
from pyglossary.lxml_types import Element
5656

5757
from .appledict_properties import AppleDictProperties
@@ -82,8 +82,8 @@ class Reader:
8282
".strings",
8383
}
8484

85-
def __init__(self, glos: GlossaryType) -> None:
86-
self._glos: GlossaryType = glos
85+
def __init__(self, glos: ReaderGlossaryType) -> None:
86+
self._glos: ReaderGlossaryType = glos
8787
self._dictDirPath = ""
8888
self._contentsPath = ""
8989
self._file: io.BufferedIOBase = nullBinaryIO

pyglossary/plugins/ayandict_sqlite/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import sqlite3
1010
from collections.abc import Iterator
1111

12-
from pyglossary.glossary_types import EntryType, GlossaryType
12+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
1313

1414

1515
class Reader:
16-
def __init__(self, glos: GlossaryType) -> None:
16+
def __init__(self, glos: ReaderGlossaryType) -> None:
1717
self._glos = glos
1818
self._clear()
1919

pyglossary/plugins/ayandict_sqlite/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sqlite3
1010
from collections.abc import Generator
1111

12-
from pyglossary.glossary_types import EntryType, GlossaryType
12+
from pyglossary.glossary_types import EntryType, WriterGlossaryType
1313
from pyglossary.xdxf.transform import XdxfTransformer
1414

1515
from pyglossary.core import log
@@ -18,7 +18,7 @@
1818
class Writer:
1919
_fuzzy: int = True
2020

21-
def __init__(self, glos: GlossaryType) -> None:
21+
def __init__(self, glos: WriterGlossaryType) -> None:
2222
self._glos = glos
2323
self._clear()
2424

pyglossary/plugins/babylon_bgl/bgl_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
if TYPE_CHECKING:
6464
from collections.abc import Iterator
6565

66-
from pyglossary.glossary_types import EntryType, GlossaryType
66+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
6767

6868
__all__ = ["BGLGzipFile", "BglReader", "Block", "FileOffS", "optionsProp", "tmpDir"]
6969

@@ -342,7 +342,7 @@ class BglReader:
342342
selected encoding, so the user may fix the encoding if needed.
343343
"""
344344

345-
def __init__(self, glos: GlossaryType) -> None: # no more arguments
345+
def __init__(self, glos: ReaderGlossaryType) -> None: # no more arguments
346346
self._glos = glos
347347
self._filename = ""
348348
self.info = {}

pyglossary/plugins/cc_kedict/reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import lxml
1313

14-
from pyglossary.glossary_types import EntryType, GlossaryType
14+
from pyglossary.glossary_types import EntryType, ReaderGlossaryType
1515

1616
from pyglossary.core import exc_note, log, pip
1717
from pyglossary.text_reader import TextGlossaryReader
@@ -29,7 +29,7 @@ class YamlReader(TextGlossaryReader):
2929

3030
def __init__( # noqa: PLR0913
3131
self,
32-
glos: GlossaryType,
32+
glos: ReaderGlossaryType,
3333
spellKey: str = "",
3434
posKey: str = "",
3535
synsKey: str = "",
@@ -272,7 +272,7 @@ class Reader:
272272
"lxml": "lxml",
273273
}
274274

275-
def __init__(self, glos: GlossaryType) -> None:
275+
def __init__(self, glos: ReaderGlossaryType) -> None:
276276
self._glos = glos
277277
self._yaml = YamlReader(
278278
glos,

0 commit comments

Comments
 (0)