From b6b889496402596d1f70ebffe835675aed874c8a Mon Sep 17 00:00:00 2001 From: GrozniyToaster <61936336+GrozniyToaster@users.noreply.github.com> Date: Fri, 26 Aug 2022 20:24:21 +0300 Subject: [PATCH] Accept anything with __getitem__ in str.translate (#8629) translate table protocol --- stdlib/builtins.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index ec6efd9ef..8e092b6fa 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -406,6 +406,9 @@ class complex: class _FormatMapMapping(Protocol): def __getitem__(self, __key: str) -> Any: ... +class _TranslateTable(Protocol): + def __getitem__(self, __key: int) -> str | int | None: ... + class str(Sequence[str]): @overload def __new__(cls: type[Self], object: object = ...) -> Self: ... @@ -535,7 +538,7 @@ class str(Sequence[str]): def title(self: LiteralString) -> LiteralString: ... @overload def title(self) -> str: ... # type: ignore[misc] - def translate(self, __table: Mapping[int, int | str | None] | Sequence[int | str | None]) -> str: ... + def translate(self, __table: _TranslateTable) -> str: ... @overload def upper(self: LiteralString) -> LiteralString: ... @overload