From e541cdd1a68aa0a17995a2f16f3a3ab87e533338 Mon Sep 17 00:00:00 2001 From: Rebecca Chen Date: Sat, 16 Mar 2019 14:12:36 -0700 Subject: [PATCH] Add unicode support to py2 string.Template. (#2871) --- stdlib/2/string.pyi | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/stdlib/2/string.pyi b/stdlib/2/string.pyi index 751fd28a0..fc06f1a0c 100644 --- a/stdlib/2/string.pyi +++ b/stdlib/2/string.pyi @@ -2,7 +2,7 @@ # Based on http://docs.python.org/3.2/library/string.html -from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable, AnyStr +from typing import Any, AnyStr, Iterable, List, Mapping, Optional, overload, Sequence, Text, Tuple, Union ascii_letters = ... # type: str ascii_lowercase = ... # type: str @@ -47,14 +47,18 @@ def center(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... def zfill(s: AnyStr, width: int) -> AnyStr: ... def replace(s: AnyStr, old: AnyStr, new: AnyStr, maxreplace: int = ...) -> AnyStr: ... -class Template(object): - # TODO: Unicode support? - template = ... # type: str +class Template: + template: Text - def __init__(self, template: str) -> None: ... - def substitute(self, mapping: Mapping[str, str] = ..., **kwds: str) -> str: ... - def safe_substitute(self, mapping: Mapping[str, str] = ..., - **kwds: str) -> str: ... + def __init__(self, template: Text) -> None: ... + @overload + def substitute(self, mapping: Mapping[Text, str] = ..., **kwds: str) -> str: ... + @overload + def substitute(self, mapping: Mapping[Text, Text] = ..., **kwds: Text) -> Text: ... + @overload + def safe_substitute(self, mapping: Mapping[Text, str] = ..., **kwds: str) -> str: ... + @overload + def safe_substitute(self, mapping: Mapping[Text, Text] = ..., **kwds: Text) -> Text: ... # TODO(MichalPokorny): This is probably badly and/or loosely typed. class Formatter(object):