From ee69dd4de7d7753ac7f0876c926f0c7d67e93049 Mon Sep 17 00:00:00 2001 From: Lourens Veen Date: Wed, 25 Nov 2020 02:27:29 +0100 Subject: [PATCH] Fix collections.Userstring.encode() (#4787) * Revert Python 2 part of ba223399, the stub was correct * Describe UserString.encode() return type correctly for Python <3.8 --- stdlib/2/UserString.pyi | 2 +- stdlib/3/collections/__init__.pyi | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/2/UserString.pyi b/stdlib/2/UserString.pyi index 8e5086cc4..df7bbc363 100644 --- a/stdlib/2/UserString.pyi +++ b/stdlib/2/UserString.pyi @@ -26,7 +26,7 @@ class UserString(Sequence[UserString]): def center(self: _UST, width: int, *args: Any) -> _UST: ... def count(self, sub: int, start: int = ..., end: int = ...) -> int: ... def decode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ... - def encode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> str: ... + def encode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ... def endswith(self, suffix: Text, start: int = ..., end: int = ...) -> bool: ... def expandtabs(self: _UST, tabsize: int = ...) -> _UST: ... def find(self, sub: Text, start: int = ..., end: int = ...) -> int: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index 600e3d500..65f1e0e95 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -137,7 +137,10 @@ class UserString(Sequence[str]): def casefold(self: _UserStringT) -> _UserStringT: ... def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... def count(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... - def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> bytes: ... + if sys.version_info >= (3, 8): + def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> bytes: ... + else: + def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UserStringT: ... def endswith(self, suffix: Union[str, Tuple[str, ...]], start: int = ..., end: int = ...) -> bool: ... def expandtabs(self: _UserStringT, tabsize: int = ...) -> _UserStringT: ... def find(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ...