Skip to content

Commit 0cffa59

Browse files
use a Protocol for str.format_map() (#4122)
Fixes #3824
1 parent ca553cd commit 0cffa59

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

stdlib/2/__builtin__.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ else:
407407

408408
_str_base = basestring
409409

410+
class _FormatMapMapping(Protocol):
411+
def __getitem__(self, __key: str) -> Any: ...
412+
410413
class str(Sequence[str], _str_base):
411414
if sys.version_info >= (3,):
412415
@overload
@@ -433,7 +436,7 @@ class str(Sequence[str], _str_base):
433436
def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
434437
def format(self, *args: object, **kwargs: object) -> str: ...
435438
if sys.version_info >= (3,):
436-
def format_map(self, map: Mapping[str, Any]) -> str: ...
439+
def format_map(self, map: _FormatMapMapping) -> str: ...
437440
def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
438441
def isalnum(self) -> bool: ...
439442
def isalpha(self) -> bool: ...

stdlib/2and3/builtins.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ else:
407407

408408
_str_base = basestring
409409

410+
class _FormatMapMapping(Protocol):
411+
def __getitem__(self, __key: str) -> Any: ...
412+
410413
class str(Sequence[str], _str_base):
411414
if sys.version_info >= (3,):
412415
@overload
@@ -433,7 +436,7 @@ class str(Sequence[str], _str_base):
433436
def find(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
434437
def format(self, *args: object, **kwargs: object) -> str: ...
435438
if sys.version_info >= (3,):
436-
def format_map(self, map: Mapping[str, Any]) -> str: ...
439+
def format_map(self, map: _FormatMapMapping) -> str: ...
437440
def index(self, sub: Text, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ...
438441
def isalnum(self) -> bool: ...
439442
def isalpha(self) -> bool: ...

0 commit comments

Comments
 (0)