Refine str.maketrans and str.translate (#1613)

str.translate requires a Mapping or Sequence (in essence, anything
with __getitem__), not a Dict.

str.maketrans in the one-argument form only converts character string
keys to their unicode ordinal, leaving any of the values untouched.
This mapping may use both integers or strings as keys at the same time.

str.maketrans in the multi-argument form returns a dict with any of the
values str, int or None, as recognized by str.translate.
This commit is contained in:
FichteFoll
2017-11-08 03:55:05 +01:00
committed by Jelle Zijlstra
parent c7bc0bdb00
commit f933b9384c
3 changed files with 7 additions and 7 deletions

View File

@@ -278,15 +278,15 @@ class str(Sequence[str]):
def strip(self, chars: Optional[str] = None) -> str: ...
def swapcase(self) -> str: ...
def title(self) -> str: ...
def translate(self, table: Dict[int, Any]) -> str: ...
def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ...
def upper(self) -> str: ...
def zfill(self, width: int) -> str: ...
@staticmethod
@overload
def maketrans(x: Union[Dict[int, Any], Dict[str, Any]]) -> Dict[int, Any]: ...
def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ...
@staticmethod
@overload
def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Any]: ...
def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ...
def __getitem__(self, i: Union[int, slice]) -> str: ...
def __add__(self, s: str) -> str: ...