Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stubs/polib/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -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__
84 changes: 65 additions & 19 deletions stubs/polib/polib.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
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)
_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: ...
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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
Expand All @@ -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: ...
Expand All @@ -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
Expand All @@ -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: ...
Expand All @@ -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: ...

Expand Down
Loading