Skip to content

Commit c7b2dde

Browse files
committed
chore(formats): simplify PoHeaderMixin typing
Avoid making it generic, but rather type limit the store.
1 parent 8827477 commit c7b2dde

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

weblate/formats/ttkit.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
PO_DOCSTRING_LOCATION = re.compile(r":docstring of [a-zA-Z0-9._]+:[0-9]+")
119119
XLIFF_FUZZY_STATES = {"new", "needs-translation", "needs-adaptation", "needs-l10n"}
120120
_CSV_MAX_PLURAL_FORMS = 100
121+
type PoHeaderUnit = pounit | PoXliffUnit
121122

122123

123124
class CSVMetadataError(ValueError):
@@ -1542,15 +1543,15 @@ def set_state(self, state) -> None:
15421543
self.unit.marktranslatable(False)
15431544

15441545

1545-
class PoHeaderMixin[
1546-
S: pofile | PoXliffFile,
1547-
U: pounit | PoXliffUnit,
1548-
T: TTKitUnit,
1549-
](TTKitFormat[S, U, T]):
1546+
class PoHeaderMixin:
1547+
store: pofile | PoXliffFile
1548+
15501549
def _po_header_store(self) -> poheader:
1551-
return self.store
1550+
return cast("poheader", self.store)
15521551

1553-
def _ensure_po_header_first(self, header: U | None = None) -> U | None:
1552+
def _ensure_po_header_first(
1553+
self, header: PoHeaderUnit | None = None
1554+
) -> PoHeaderUnit | None:
15541555
"""Keep PO-style header in the position expected by Translate Toolkit."""
15551556
units = self.store.units
15561557
if header is None:
@@ -1640,7 +1641,9 @@ def update_header(self, file_format_params: FileFormatParams, **kwargs) -> None:
16401641
self._ensure_po_header_first(store.updateheader(add=True, **kwargs))
16411642

16421643

1643-
class BasePoFormat[S: pofile, U: pounit, T: BasePoUnit](PoHeaderMixin[S, U, T]):
1644+
class BasePoFormat[S: pofile, U: pounit, T: BasePoUnit](
1645+
PoHeaderMixin, TTKitFormat[S, U, T]
1646+
):
16441647
loader = pofile # type: ignore[assignment]
16451648
plural_preference: tuple[int, ...] | None = None
16461649
supports_plural: bool = True
@@ -1832,10 +1835,7 @@ class RichXliffFormat(XliffFormat):
18321835
unit_class = RichXliffUnit
18331836

18341837

1835-
class PoXliffFormat(
1836-
PoHeaderMixin[PoXliffFile, PoXliffUnit, XliffUnit[PoXliffUnit, XliffFormat]],
1837-
XliffFormat,
1838-
):
1838+
class PoXliffFormat(PoHeaderMixin, XliffFormat):
18391839
# Translators: File format name
18401840
name = gettext_lazy("XLIFF 1.2 with gettext extensions")
18411841
format_id = "poxliff"

0 commit comments

Comments
 (0)