From d760d48f5269262cb3f904e80e24785588e4a83f Mon Sep 17 00:00:00 2001 From: David Euresti Date: Fri, 5 Aug 2016 07:47:23 -0700 Subject: [PATCH] Copy string.Formatter to python 3 (#443) --- stdlib/3/string.pyi | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/stdlib/3/string.pyi b/stdlib/3/string.pyi index bc35bb388..e2c7291ed 100644 --- a/stdlib/3/string.pyi +++ b/stdlib/3/string.pyi @@ -2,7 +2,7 @@ # Based on http://docs.python.org/3.2/library/string.html -from typing import Mapping +from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable, AnyStr ascii_letters = ... # type: str ascii_lowercase = ... # type: str @@ -24,4 +24,19 @@ class Template: def safe_substitute(self, mapping: Mapping[str, str], **kwds: str) -> str: ... -# TODO Formatter +# TODO(MichalPokorny): This is probably badly and/or loosely typed. +class Formatter(object): + def format(self, format_string: str, *args, **kwargs) -> str: ... + def vformat(self, format_string: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> str: ... + def parse(self, format_string: str) -> Iterable[Tuple[str, Optional[str], Optional[str], Optional[str]]]: ... + def get_field(self, field_name: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: ... + def get_value(self, key: Union[int, str], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: + raise IndexError() + raise KeyError() + def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> None: ... + def format_field(self, value: Any, format_spec: str) -> Any: ... + def convert_field(self, value: Any, conversion: str) -> Any: ...