From c3c6abc1531669b7dcb03d71ff21f09757ae78b6 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Wed, 27 May 2020 21:26:58 -0700 Subject: [PATCH] gettext: various fixes (#4125) --- stdlib/3/gettext.pyi | 32 +++++++++++++----------- tests/stubtest_whitelists/py35.txt | 6 ----- tests/stubtest_whitelists/py36.txt | 6 ----- tests/stubtest_whitelists/py37.txt | 6 ----- tests/stubtest_whitelists/py3_common.txt | 9 ------- 5 files changed, 18 insertions(+), 41 deletions(-) diff --git a/stdlib/3/gettext.pyi b/stdlib/3/gettext.pyi index 8469c3d5e..7c6062c48 100644 --- a/stdlib/3/gettext.pyi +++ b/stdlib/3/gettext.pyi @@ -1,5 +1,5 @@ import sys -from typing import overload, Any, Container, IO, Iterable, Optional, Type, TypeVar, Union +from typing import overload, Any, Container, IO, Iterable, Optional, Sequence, Type, TypeVar, Union if sys.version_info >= (3, 8): from typing import Literal @@ -13,15 +13,16 @@ else: _Path = str class NullTranslations: - def __init__(self, fp: IO[str] = ...) -> None: ... + def __init__(self, fp: Optional[IO[str]] = ...) -> None: ... def _parse(self, fp: IO[str]) -> None: ... def add_fallback(self, fallback: NullTranslations) -> None: ... def gettext(self, message: str) -> str: ... def lgettext(self, message: str) -> str: ... - def ngettext(self, singular: str, plural: str, n: int) -> str: ... - def lngettext(self, singular: str, plural: str, n: int) -> str: ... - def pgettext(self, context: str, message: str) -> str: ... - def npgettext(self, context: str, msgid1: str, msgid2: str, n: int) -> str: ... + def ngettext(self, msgid1: str, msgid2: str, n: int) -> str: ... + def lngettext(self, msgid1: str, msgid2: str, n: int) -> str: ... + if sys.version_info >= (3, 8): + 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 output_charset(self) -> Any: ... @@ -31,6 +32,8 @@ class NullTranslations: class GNUTranslations(NullTranslations): LE_MAGIC: int BE_MAGIC: int + CONTEXT: str + VERSIONS: Sequence[int] def find(domain: str, localedir: Optional[_Path] = ..., languages: Optional[Iterable[str]] = ..., all: bool = ...) -> Any: ... @@ -54,15 +57,16 @@ def bindtextdomain(domain: str, localedir: Optional[_Path] = ...) -> str: ... def bind_textdomain_codeset(domain: str, codeset: Optional[str] = ...) -> str: ... def dgettext(domain: str, message: str) -> str: ... def ldgettext(domain: str, message: str) -> str: ... -def dngettext(domain: str, singular: str, plural: str, n: int) -> str: ... -def ldngettext(domain: str, singular: str, plural: str, n: int) -> str: ... +def dngettext(domain: str, msgid1: str, msgid2: str, n: int) -> str: ... +def ldngettext(domain: str, msgid1: str, msgid2: str, n: int) -> str: ... def gettext(message: str) -> str: ... def lgettext(message: str) -> str: ... -def ngettext(singular: str, plural: str, n: int) -> str: ... -def lngettext(singular: str, plural: str, n: int) -> str: ... -def pgettext(context: str, message: str) -> str: ... -def dpgettext(domain: str, context: str, message: str) -> str: ... -def npgettext(context: str, msgid1: str, msgid2: str, n: int) -> str: ... -def dnpgettext(domain: str, context: str, msgid1: str, msgid2: str, n: int) -> str: ... +def ngettext(msgid1: str, msgid2: str, n: int) -> str: ... +def lngettext(msgid1: str, msgid2: str, n: int) -> str: ... +if sys.version_info >= (3, 8): + def pgettext(context: str, message: str) -> str: ... + def dpgettext(domain: str, context: str, message: str) -> str: ... + def npgettext(context: str, msgid1: str, msgid2: str, n: int) -> str: ... + def dnpgettext(domain: str, context: str, msgid1: str, msgid2: str, n: int) -> str: ... Catalog = translation diff --git a/tests/stubtest_whitelists/py35.txt b/tests/stubtest_whitelists/py35.txt index a711590e0..968b98b8a 100644 --- a/tests/stubtest_whitelists/py35.txt +++ b/tests/stubtest_whitelists/py35.txt @@ -22,12 +22,6 @@ collections.UserString.maketrans contextlib._GeneratorContextManager.__init__ ctypes.CDLL.__init__ fractions.Fraction.__new__ # private _normalize param was made keyword-only in Python 3.6 -gettext.NullTranslations.npgettext -gettext.NullTranslations.pgettext -gettext.dnpgettext -gettext.dpgettext -gettext.npgettext -gettext.pgettext importlib.metadata importlib.resources io.BufferedRandom.read1 diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index 8abd0c35c..7c59c628c 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -20,12 +20,6 @@ copy.PyStringMap ctypes.CDLL.__init__ email.message.MIMEPart.as_string enum.Enum._generate_next_value_ -gettext.NullTranslations.npgettext -gettext.NullTranslations.pgettext -gettext.dnpgettext -gettext.dpgettext -gettext.npgettext -gettext.pgettext importlib.metadata importlib.resources io.BufferedRandom.read1 diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index 2649ed1fb..36ca263aa 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -31,12 +31,6 @@ dataclasses.Field.__init__ dataclasses.field email.message.MIMEPart.as_string enum.Enum._generate_next_value_ -gettext.NullTranslations.npgettext -gettext.NullTranslations.pgettext -gettext.dnpgettext -gettext.dpgettext -gettext.npgettext -gettext.pgettext http.client.HTTPSConnection.__init__ http.server.SimpleHTTPRequestHandler.__init__ importlib.metadata diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 26fe84bfe..cb859e668 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -210,15 +210,6 @@ encodings.utf_8.encode enum.EnumMeta.__call__ enum.EnumMeta.__new__ getopt.GetoptError.__init__ -gettext.GNUTranslations.lngettext -gettext.GNUTranslations.ngettext -gettext.NullTranslations.__init__ -gettext.NullTranslations.lngettext -gettext.NullTranslations.ngettext -gettext.dngettext -gettext.ldngettext -gettext.lngettext -gettext.ngettext hmac.HMAC.__init__ html.parser.HTMLParser.feed http.HTTPStatus.description