From 7c3edba6ce3ca98b145bcf49ec7c8d7a5dc6606b Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Sat, 16 Jun 2018 19:19:24 +0200 Subject: [PATCH] python2/gettext improvements (#2235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * py2: gettext: info() returns a Dict[str, str] > Return the “protected” _info variable. > The entire set of key/value pairs are placed into a dictionary and set > as the “protected” _info instance variable. * py2: gettext: charset() returns an Optional[str] > Return the “protected” _charset variable. > If the key Content-Type is found, then the charset property is used to > initialize the “protected” _charset instance variable, defaulting to > None if not found. * py2: gettext: [set_]output_charset() allows to set an Optional[str] > Return the “protected” _output_charset variable. > Change the “protected” _output_charset variable, which defines the > encoding used to return translated messages. > Equivalent to gettext(), but the translation is returned in the > preferred system encoding, if no other encoding was explicitly set with > set_output_charset(). * py2: gettext: install(..., names) allows to set an Optional[str] > If the names parameter is given, it must be a sequence containing the > names of functions you want to install in the builtins namespace in > addition to _(). * py2: gettext: localdir=None is Optional[str] > If localedir is omitted or None, then the current binding for domain > is returned. * py2: gettext: languages=None is Optional[Sequence[str]] > If languages is not given, then the following environment variables > are searched: ... * py2: gettext: codeset=None is Optional[str] > If provided, codeset will change the charset used to encode translated > strings. * py2: gettext: translation(class_=None) is Optional[type] > The actual class instantiated is either class_ if provided, otherwise > GNUTranslations. * py2: gettext: translation(fallback) is bool > ..., this function raises IOError if fallback is false (which is the > default), and returns a NullTranslations instance if fallback is true. * py2: gettext: install(unicode) is bool > The unicode flag is passed to the resulting translation object’s > install() method. which is already expecting `bool`. --- stdlib/2/gettext.pyi | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/stdlib/2/gettext.pyi b/stdlib/2/gettext.pyi index 51dd52345..a12d54123 100644 --- a/stdlib/2/gettext.pyi +++ b/stdlib/2/gettext.pyi @@ -1,6 +1,4 @@ -# TODO(MichalPokorny): better types - -from typing import Any, IO, List, Optional, Union +from typing import Any, Container, Dict, IO, List, Optional, Sequence, Type, Union def bindtextdomain(domain: str, localedir: str = ...) -> str: ... def bind_textdomain_codeset(domain: str, codeset: str = ...) -> str: ... @@ -24,20 +22,20 @@ class NullTranslations(object): def ngettext(self, singular: str, plural: str, n: int) -> str: ... def lngettext(self, singular: str, plural: str, n: int) -> str: ... def ungettext(self, singular: Union[str, unicode], plural: Union[str, unicode], n: int) -> unicode: ... - def info(self) -> Any: ... - def charset(self) -> Any: ... - def output_charset(self) -> Any: ... - def set_output_charset(self, charset: Any) -> None: ... - def install(self, unicode: bool = ..., names: Any = ...) -> None: ... + def info(self) -> Dict[str, str]: ... + def charset(self) -> Optional[str]: ... + def output_charset(self) -> Optional[str]: ... + def set_output_charset(self, charset: Optional[str]) -> None: ... + def install(self, unicode: bool = ..., names: Container[str] = ...) -> None: ... class GNUTranslations(NullTranslations): LE_MAGIC = ... # type: int BE_MAGIC = ... # type: int -def find(domain: str, localedir: str = ..., languages: List[str] = ..., +def find(domain: str, localedir: Optional[str] = ..., languages: Optional[Sequence[str]] = ..., all: Any = ...) -> Optional[Union[str, List[str]]]: ... -def translation(domain: str, localedir: str = ..., languages: List[str] = ..., - class_: Any = ..., fallback: Any = ..., codeset: Any = ...) -> NullTranslations: ... -def install(domain: str, localedir: str = ..., unicode: Any = ..., codeset: Any = ..., - names: Any = ...) -> None: ... +def translation(domain: str, localedir: Optional[str] = ..., languages: Optional[Sequence[str]] = ..., + class_: Optional[Type[NullTranslations]] = ..., fallback: bool = ..., codeset: Optional[str] = ...) -> NullTranslations: ... +def install(domain: str, localedir: Optional[str] = ..., unicode: bool = ..., codeset: Optional[str] = ..., + names: Container[str] = ...) -> None: ...