From 182fa6321cb3eabd308139bea6dce1d2dd6ccf1c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 16 Apr 2022 16:07:15 +0200 Subject: [PATCH] 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 --- stdlib/gettext.pyi | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/stdlib/gettext.pyi b/stdlib/gettext.pyi index 1f3ef67ab..d02dda535 100644 --- a/stdlib/gettext.pyi +++ b/stdlib/gettext.pyi @@ -1,7 +1,8 @@ import sys from _typeshed import StrPath -from typing import IO, Any, Container, Iterable, Sequence, TypeVar, overload -from typing_extensions import Literal +from collections.abc import Container, Iterable, Sequence +from typing import Any, Protocol, TypeVar, overload +from typing_extensions import Final, Literal if sys.version_info >= (3, 11): __all__ = [ @@ -67,9 +68,14 @@ else: "ngettext", ] +class _TranslationsReader(Protocol): + def read(self) -> bytes: ... + # optional: + # name: str + class NullTranslations: - def __init__(self, fp: IO[str] | None = ...) -> None: ... - def _parse(self, fp: IO[str]) -> None: ... + def __init__(self, fp: _TranslationsReader | None = ...) -> None: ... + def _parse(self, fp: _TranslationsReader) -> None: ... def add_fallback(self, fallback: NullTranslations) -> None: ... def gettext(self, message: str) -> str: ... def lgettext(self, message: str) -> str: ... @@ -79,18 +85,18 @@ class NullTranslations: def pgettext(self, context: str, message: str) -> str: ... def npgettext(self, context: str, msgid1: str, msgid2: str, n: int) -> str: ... - def info(self) -> Any: ... - def charset(self) -> Any: ... + def info(self) -> dict[str, str]: ... + def charset(self) -> str | None: ... if sys.version_info < (3, 11): - def output_charset(self) -> Any: ... + def output_charset(self) -> str | None: ... def set_output_charset(self, charset: str) -> None: ... def install(self, names: Container[str] | None = ...) -> None: ... class GNUTranslations(NullTranslations): - LE_MAGIC: int - BE_MAGIC: int - CONTEXT: str + LE_MAGIC: Final[int] + BE_MAGIC: Final[int] + CONTEXT: Final[str] VERSIONS: Sequence[int] @overload # ignores incompatible overloads