Skip to content

Commit 182fa63

Browse files
authored
Update gettext translations (#7636)
* Use a protocol instead of `IO` for `fp` argument. * Annotate a few missing return types. * Mark some class constants as final. Fixes #7628
1 parent 653f2c6 commit 182fa63

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

stdlib/gettext.pyi

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
22
from _typeshed import StrPath
3-
from typing import IO, Any, Container, Iterable, Sequence, TypeVar, overload
4-
from typing_extensions import Literal
3+
from collections.abc import Container, Iterable, Sequence
4+
from typing import Any, Protocol, TypeVar, overload
5+
from typing_extensions import Final, Literal
56

67
if sys.version_info >= (3, 11):
78
__all__ = [
@@ -67,9 +68,14 @@ else:
6768
"ngettext",
6869
]
6970

71+
class _TranslationsReader(Protocol):
72+
def read(self) -> bytes: ...
73+
# optional:
74+
# name: str
75+
7076
class NullTranslations:
71-
def __init__(self, fp: IO[str] | None = ...) -> None: ...
72-
def _parse(self, fp: IO[str]) -> None: ...
77+
def __init__(self, fp: _TranslationsReader | None = ...) -> None: ...
78+
def _parse(self, fp: _TranslationsReader) -> None: ...
7379
def add_fallback(self, fallback: NullTranslations) -> None: ...
7480
def gettext(self, message: str) -> str: ...
7581
def lgettext(self, message: str) -> str: ...
@@ -79,18 +85,18 @@ class NullTranslations:
7985
def pgettext(self, context: str, message: str) -> str: ...
8086
def npgettext(self, context: str, msgid1: str, msgid2: str, n: int) -> str: ...
8187

82-
def info(self) -> Any: ...
83-
def charset(self) -> Any: ...
88+
def info(self) -> dict[str, str]: ...
89+
def charset(self) -> str | None: ...
8490
if sys.version_info < (3, 11):
85-
def output_charset(self) -> Any: ...
91+
def output_charset(self) -> str | None: ...
8692
def set_output_charset(self, charset: str) -> None: ...
8793

8894
def install(self, names: Container[str] | None = ...) -> None: ...
8995

9096
class GNUTranslations(NullTranslations):
91-
LE_MAGIC: int
92-
BE_MAGIC: int
93-
CONTEXT: str
97+
LE_MAGIC: Final[int]
98+
BE_MAGIC: Final[int]
99+
CONTEXT: Final[str]
94100
VERSIONS: Sequence[int]
95101

96102
@overload # ignores incompatible overloads

0 commit comments

Comments
 (0)