From 6f1aeaa10906acaba73e997c439f98faa9cf1730 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Nov 2026 13:47:40 +0100 Subject: [PATCH 1/2] [polib] Replace `Any` and `IO` --- stubs/polib/polib.pyi | 84 +++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/stubs/polib/polib.pyi b/stubs/polib/polib.pyi index 63279e7c3722..3b6910251cde 100644 --- a/stubs/polib/polib.pyi +++ b/stubs/polib/polib.pyi @@ -1,7 +1,8 @@ from _typeshed import StrOrBytesPath from collections.abc import Callable +from io import BufferedReader, BytesIO, TextIOWrapper from pathlib import Path -from typing import IO, Any, Generic, Literal, SupportsIndex, TypeVar, overload +from typing import Final, Generic, Literal, SupportsIndex, TypeVar, overload _TB = TypeVar("_TB", bound=_BaseEntry) _TP = TypeVar("_TP", bound=POFile) @@ -9,18 +10,21 @@ _TM = TypeVar("_TM", bound=MOFile) default_encoding: str -# wrapwidth: int -# encoding: str -# check_for_duplicates: bool @overload -def pofile(pofile: str | Path, *, klass: type[_TP], **kwargs: Any) -> _TP: ... +def pofile( + pofile: str | Path, *, klass: type[_TP], wrapwidth: int = 78, encoding: str | None = None, check_for_duplicates: bool = False +) -> _TP: ... @overload -def pofile(pofile: str | Path, **kwargs: Any) -> POFile: ... +def pofile( + pofile: str | Path, *, wrapwidth: int = 78, encoding: str | None = None, check_for_duplicates: bool = False +) -> POFile: ... @overload -def mofile(mofile: str, *, klass: type[_TM], **kwargs: Any) -> _TM: ... +def mofile( + mofile: str, *, klass: type[_TM], wrapwidth: int = 78, encoding: str | None = None, check_for_duplicates: bool = False +) -> _TM: ... @overload -def mofile(mofile: str, **kwargs: Any) -> MOFile: ... +def mofile(mofile: str, *, wrapwidth: int = 78, encoding: str | None = None, check_for_duplicates: bool = False) -> MOFile: ... def detect_encoding(file: bytes | str, binary_mode: bool = ...) -> str: ... def escape(st: str) -> str: ... @@ -34,7 +38,7 @@ class _BaseFile(list[_TB]): header: str metadata: dict[str, str] metadata_is_fuzzy: bool - def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __init__(self, *, pofile: StrOrBytesPath | None = None, fpath: StrOrBytesPath | None = None) -> None: ... def __unicode__(self) -> str: ... def __contains__(self, entry: _TB) -> bool: ... # type: ignore[override] # AttributeError otherwise def __eq__(self, other: object) -> bool: ... @@ -59,11 +63,13 @@ class POFile(_BaseFile[POEntry]): def merge(self, refpot: POFile) -> None: ... class MOFile(_BaseFile[MOEntry]): - MAGIC: int - MAGIC_SWAPPED: int + MAGIC: Final[int] + MAGIC_SWAPPED: Final[int] + magic_number: int | None version: int - def __init__(self, *args: Any, **kwargs: Any) -> None: ... + + def __init__(self, *, pofile: StrOrBytesPath | None = None, fpath: StrOrBytesPath | None = None) -> None: ... def save_as_pofile(self, fpath: str) -> None: ... def save(self, fpath: str | None = ...) -> None: ... # type: ignore[override] # binary file does not allow argument repr_method def percent_translated(self) -> int: ... @@ -80,7 +86,17 @@ class _BaseEntry: msgctxt: str | None obsolete: bool encoding: str - def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __init__( + self, + *, + msgid: str = "", + msgstr: str = "", + msgid_plural: str = "", + msgstr_plural: dict[int, str] = {}, + msgctx: str | None = None, + obsolete: bool = False, + encoding: str = ..., + ) -> None: ... def __unicode__(self, wrapwidth: int = ...) -> str: ... def __eq__(self, other: object) -> bool: ... @property @@ -95,7 +111,25 @@ class POEntry(_BaseEntry): previous_msgid: str | None previous_msgid_plural: str | None linenum: int | None - def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __init__( + self, + *, + msgid: str = "", + msgstr: str = "", + msgid_plural: str = "", + msgstr_plural: dict[int, str] = {}, + msgctx: str | None = None, + obsolete: bool = False, + encoding: str = ..., + comment: str = ..., + tcomment: str = ..., + occurrences: list[tuple[str, str]] = [], + flags: list[str] = [], + previous_msgctxt: str | None = None, + previous_msgid: str | None = None, + previous_msgid_plural: str | None = None, + linenum: int | None = None, + ) -> None: ... def __unicode__(self, wrapwidth: int = ...) -> str: ... def __cmp__(self, other: POEntry) -> int: ... def __gt__(self, other: POEntry) -> bool: ... @@ -120,11 +154,21 @@ class MOEntry(_BaseEntry): previous_msgctxt: str | None previous_msgid: str | None previous_msgid_plural: str | None - def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __init__( + self, + *, + msgid: str = "", + msgstr: str = "", + msgid_plural: str = "", + msgstr_plural: dict[int, str] = {}, + msgctx: str | None = None, + obsolete: bool = False, + encoding: str = ..., + ) -> None: ... def __hash__(self) -> int: ... class _POFileParser(Generic[_TP]): - fhandle: IO[str] + fhandle: list[str] | TextIOWrapper instance: _TP transitions: dict[tuple[str, str], tuple[Callable[[], bool], str]] current_line: int @@ -133,7 +177,7 @@ class _POFileParser(Generic[_TP]): current_token: str | None msgstr_index: int entry_obsolete: int - def __init__(self, pofile: str, *args: Any, **kwargs: Any) -> None: ... + def __init__(self, pofile: str, *, encoding: str = ..., check_for_duplicates: bool = False) -> None: ... def parse(self) -> _TP: ... def add(self, symbol: str, states: list[str], next_state: str) -> None: ... def process(self, symbol: str) -> None: ... @@ -153,9 +197,11 @@ class _POFileParser(Generic[_TP]): def handle_mc(self) -> bool: ... class _MOFileParser(Generic[_TM]): - fhandle: IO[bytes] + fhandle: BufferedReader | BytesIO instance: _TM - def __init__(self, mofile: str, *args: Any, **kwargs: Any) -> None: ... + def __init__( + self, mofile: str, *, klass: type[MOFile] = MOFile, encoding: str = ..., check_for_duplicates: bool = False # noqa: Y011 + ) -> None: ... def __del__(self) -> None: ... def parse(self) -> _TM: ... From 9fc8534b9961247a7ef24c87a7933d1494b68a00 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Nov 2026 13:52:24 +0100 Subject: [PATCH 2/2] Add stubtest allowlist --- stubs/polib/@tests/stubtest_allowlist.txt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 stubs/polib/@tests/stubtest_allowlist.txt diff --git a/stubs/polib/@tests/stubtest_allowlist.txt b/stubs/polib/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..478f434171d5 --- /dev/null +++ b/stubs/polib/@tests/stubtest_allowlist.txt @@ -0,0 +1,8 @@ +# Implementation has "*args" argument which is ignored. +polib.MOEntry.__init__ +polib.MOFile.__init__ +polib.POEntry.__init__ +polib._BaseEntry.__init__ +polib._BaseFile.__init__ +polib._MOFileParser.__init__ +polib._POFileParser.__init__