From 0cdfca1ad729e9518a2cf2110a9e671868a46272 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 27 May 2020 19:47:38 -0700 Subject: [PATCH] use a Protocol for str.format_map() Fixes #3824 --- stdlib/2/__builtin__.pyi | 5 ++++- stdlib/2and3/builtins.pyi | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 044819e0fcb7..e5360ee1ef1e 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -407,6 +407,9 @@ else: _str_base = basestring +class _FormatMapMapping(Protocol): + def __getitem__(self, __key: str) -> Any: ... + class str(Sequence[str], _str_base): if sys.version_info >= (3,): @overload @@ -433,7 +436,7 @@ class str(Sequence[str], _str_base): def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: object, **kwargs: object) -> str: ... if sys.version_info >= (3,): - def format_map(self, map: Mapping[str, Any]) -> str: ... + def format_map(self, map: _FormatMapMapping) -> str: ... def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 044819e0fcb7..e5360ee1ef1e 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -407,6 +407,9 @@ else: _str_base = basestring +class _FormatMapMapping(Protocol): + def __getitem__(self, __key: str) -> Any: ... + class str(Sequence[str], _str_base): if sys.version_info >= (3,): @overload @@ -433,7 +436,7 @@ class str(Sequence[str], _str_base): def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def format(self, *args: object, **kwargs: object) -> str: ... if sys.version_info >= (3,): - def format_map(self, map: Mapping[str, Any]) -> str: ... + def format_map(self, map: _FormatMapMapping) -> str: ... def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... def isalnum(self) -> bool: ... def isalpha(self) -> bool: ...