From 2764b471b15b5fb54579f8613cc17e0c32d28c7e Mon Sep 17 00:00:00 2001 From: Graham Bleaney Date: Wed, 27 Apr 2022 11:53:17 -0400 Subject: [PATCH 1/4] Add LiteralString overloads to str class --- stdlib/builtins.pyi | 93 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 88ec36de5720..4460ab1f03cf 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -49,7 +49,7 @@ from typing import ( # noqa: Y027 TypeVar, overload, ) -from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard, final +from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -394,8 +394,17 @@ class str(Sequence[str]): def __new__(cls: type[Self], object: object = ...) -> Self: ... @overload def __new__(cls: type[Self], object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... + @overload + def capitalize(self: LiteralString) -> LiteralString: ... + @overload def capitalize(self) -> str: ... + @overload + def casefold(self: LiteralString) -> LiteralString: ... + @overload def casefold(self) -> str: ... + @overload + def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... @@ -403,11 +412,20 @@ class str(Sequence[str]): self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ... ) -> bool: ... if sys.version_info >= (3, 8): + @overload + def expandtabs(self: LiteralString, tabsize: SupportsIndex = ...) -> LiteralString: ... + @overload def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ... else: + @overload + def expandtabs(self: LiteralString, tabsize: int = ...) -> LiteralString: ... + @overload def expandtabs(self, tabsize: int = ...) -> str: ... def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... + @overload + def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... + @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, map: _FormatMapMapping) -> str: ... def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... @@ -425,32 +443,87 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... + @overload + def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ... + @overload def join(self, __iterable: Iterable[str]) -> str: ... + @overload + def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + @overload + def lower(self: LiteralString) -> LiteralString: ... + @overload def lower(self) -> str: ... + @overload + def lstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def lstrip(self, __chars: str | None = ...) -> str: ... + @overload + def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def partition(self, __sep: str) -> tuple[str, str, str]: ... + @overload + def replace(self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...) -> LiteralString: ... + @overload def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... if sys.version_info >= (3, 9): + @overload + def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ... + @overload def removeprefix(self, __prefix: str) -> str: ... + @overload + def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ... + @overload def removesuffix(self, __suffix: str) -> str: ... - def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... - def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... + @overload + def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + @overload + def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def rpartition(self, __sep: str) -> tuple[str, str, str]: ... + @overload + def rsplit(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... + @overload def rsplit(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + @overload + def rstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def rstrip(self, __chars: str | None = ...) -> str: ... + @overload + def split(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... + @overload def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + @overload + def splitlines(self: LiteralString, keepends: bool = ...) -> list[LiteralString]: ... + @overload def splitlines(self, keepends: bool = ...) -> list[str]: ... def startswith( self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ... ) -> bool: ... + @overload + def strip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def strip(self, __chars: str | None = ...) -> str: ... + @overload + def swapcase(self: LiteralString) -> LiteralString: ... + @overload def swapcase(self) -> str: ... + @overload + def title(self: LiteralString) -> LiteralString: ... + @overload def title(self) -> str: ... def translate(self, __table: Mapping[int, int | str | None] | Sequence[int | str | None]) -> str: ... + @overload + def upper(self: LiteralString) -> LiteralString: ... + @overload def upper(self) -> str: ... + @overload + def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ... + @overload def zfill(self, __width: SupportsIndex) -> str: ... @staticmethod @overload @@ -458,6 +531,9 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(__x: str, __y: str, __z: str | None = ...) -> dict[int, int | None]: ... + @overload + def __add__(self: LiteralString, __s: LiteralString) -> LiteralString: ... + @overload def __add__(self, __s: str) -> str: ... # Incompatible with Sequence.__contains__ def __contains__(self, __o: str) -> bool: ... # type: ignore[override] @@ -466,14 +542,23 @@ class str(Sequence[str]): def __getitem__(self, __i: SupportsIndex | slice) -> str: ... def __gt__(self, __x: str) -> bool: ... def __hash__(self) -> int: ... + @overload + def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... + @overload def __iter__(self) -> Iterator[str]: ... def __le__(self, __x: str) -> bool: ... def __len__(self) -> int: ... def __lt__(self, __x: str) -> bool: ... + @overload + def __mod__(self: LiteralString, __x: Union[LiteralString, Tuple[LiteralString, ...]]) -> LiteralString: ... + @overload def __mod__(self, __x: Any) -> str: ... + @overload + def __mul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ... + @overload def __mul__(self, __n: SupportsIndex) -> str: ... def __ne__(self, __x: object) -> bool: ... - def __rmul__(self, __n: SupportsIndex) -> str: ... + def __rmul__(self, n: SupportsIndex) -> str: ... def __getnewargs__(self) -> tuple[str]: ... class bytes(ByteString): From 56aab63e112029e13bed45b5011d82744f4eeaa0 Mon Sep 17 00:00:00 2001 From: Graham Bleaney Date: Wed, 27 Apr 2022 11:53:17 -0400 Subject: [PATCH 2/4] Add LiteralString overloads to str class --- stdlib/builtins.pyi | 89 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 88ec36de5720..cb66f5bbe3ed 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -49,7 +49,7 @@ from typing import ( # noqa: Y027 TypeVar, overload, ) -from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard, final +from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -394,8 +394,17 @@ class str(Sequence[str]): def __new__(cls: type[Self], object: object = ...) -> Self: ... @overload def __new__(cls: type[Self], object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... + @overload + def capitalize(self: LiteralString) -> LiteralString: ... + @overload def capitalize(self) -> str: ... + @overload + def casefold(self: LiteralString) -> LiteralString: ... + @overload def casefold(self) -> str: ... + @overload + def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... @@ -403,11 +412,20 @@ class str(Sequence[str]): self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ... ) -> bool: ... if sys.version_info >= (3, 8): + @overload + def expandtabs(self: LiteralString, tabsize: SupportsIndex = ...) -> LiteralString: ... + @overload def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ... else: + @overload + def expandtabs(self: LiteralString, tabsize: int = ...) -> LiteralString: ... + @overload def expandtabs(self, tabsize: int = ...) -> str: ... def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... + @overload + def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... + @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, map: _FormatMapMapping) -> str: ... def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... @@ -425,32 +443,89 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... + @overload + def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ... + @overload def join(self, __iterable: Iterable[str]) -> str: ... + @overload + def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + @overload + def lower(self: LiteralString) -> LiteralString: ... + @overload def lower(self) -> str: ... + @overload + def lstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def lstrip(self, __chars: str | None = ...) -> str: ... + @overload + def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def partition(self, __sep: str) -> tuple[str, str, str]: ... + @overload + def replace(self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...) -> LiteralString: ... + @overload def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... if sys.version_info >= (3, 9): + @overload + def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ... + @overload def removeprefix(self, __prefix: str) -> str: ... + @overload + def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ... + @overload def removesuffix(self, __suffix: str) -> str: ... def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... + @overload + def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... + @overload def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + @overload + def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def rpartition(self, __sep: str) -> tuple[str, str, str]: ... + @overload + def rsplit(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... + @overload def rsplit(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + @overload + def rstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def rstrip(self, __chars: str | None = ...) -> str: ... + @overload + def split(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... + @overload def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + @overload + def splitlines(self: LiteralString, keepends: bool = ...) -> list[LiteralString]: ... + @overload def splitlines(self, keepends: bool = ...) -> list[str]: ... def startswith( self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ... ) -> bool: ... + @overload + def strip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... + @overload def strip(self, __chars: str | None = ...) -> str: ... + @overload + def swapcase(self: LiteralString) -> LiteralString: ... + @overload def swapcase(self) -> str: ... + @overload + def title(self: LiteralString) -> LiteralString: ... + @overload def title(self) -> str: ... def translate(self, __table: Mapping[int, int | str | None] | Sequence[int | str | None]) -> str: ... + @overload + def upper(self: LiteralString) -> LiteralString: ... + @overload def upper(self) -> str: ... + @overload + def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ... + @overload def zfill(self, __width: SupportsIndex) -> str: ... @staticmethod @overload @@ -458,6 +533,9 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(__x: str, __y: str, __z: str | None = ...) -> dict[int, int | None]: ... + @overload + def __add__(self: LiteralString, __s: LiteralString) -> LiteralString: ... + @overload def __add__(self, __s: str) -> str: ... # Incompatible with Sequence.__contains__ def __contains__(self, __o: str) -> bool: ... # type: ignore[override] @@ -466,11 +544,20 @@ class str(Sequence[str]): def __getitem__(self, __i: SupportsIndex | slice) -> str: ... def __gt__(self, __x: str) -> bool: ... def __hash__(self) -> int: ... + @overload + def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... + @overload def __iter__(self) -> Iterator[str]: ... def __le__(self, __x: str) -> bool: ... def __len__(self) -> int: ... def __lt__(self, __x: str) -> bool: ... + @overload + def __mod__(self: LiteralString, __x: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ... + @overload def __mod__(self, __x: Any) -> str: ... + @overload + def __mul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ... + @overload def __mul__(self, __n: SupportsIndex) -> str: ... def __ne__(self, __x: object) -> bool: ... def __rmul__(self, __n: SupportsIndex) -> str: ... From 49bc038d0d2293f5c2a47cf09171b27510e27d32 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Apr 2022 16:45:59 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/builtins.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index cb66f5bbe3ed..c9a1131b6b35 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -464,7 +464,9 @@ class str(Sequence[str]): @overload def partition(self, __sep: str) -> tuple[str, str, str]: ... @overload - def replace(self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...) -> LiteralString: ... + def replace( + self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ... + ) -> LiteralString: ... @overload def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... if sys.version_info >= (3, 9): From fb7f3d3f207b1078641f5fd89294e93e1b52b37b Mon Sep 17 00:00:00 2001 From: Graham Bleaney Date: Mon, 30 May 2022 09:22:20 -0400 Subject: [PATCH 4/4] Add type error supression to handle mypy thinking LiteralString = str --- stdlib/builtins.pyi | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 87ca1c73d3e8..ecd4adbf0756 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -397,15 +397,15 @@ class str(Sequence[str]): @overload def capitalize(self: LiteralString) -> LiteralString: ... @overload - def capitalize(self) -> str: ... + def capitalize(self) -> str: ... # type: ignore[misc] @overload def casefold(self: LiteralString) -> LiteralString: ... @overload - def casefold(self) -> str: ... + def casefold(self) -> str: ... # type: ignore[misc] @overload def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... @overload - def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc] def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... def endswith( @@ -415,18 +415,18 @@ class str(Sequence[str]): @overload def expandtabs(self: LiteralString, tabsize: SupportsIndex = ...) -> LiteralString: ... @overload - def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ... + def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ... # type: ignore[misc] else: @overload def expandtabs(self: LiteralString, tabsize: int = ...) -> LiteralString: ... @overload - def expandtabs(self, tabsize: int = ...) -> str: ... + def expandtabs(self, tabsize: int = ...) -> str: ... # type: ignore[misc] def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... @overload def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... @overload - def format(self, *args: object, **kwargs: object) -> str: ... + def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore[misc] def format_map(self, map: _FormatMapMapping) -> str: ... def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def isalnum(self) -> bool: ... @@ -446,87 +446,87 @@ class str(Sequence[str]): @overload def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ... @overload - def join(self, __iterable: Iterable[str]) -> str: ... + def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc] @overload def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... @overload - def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc] @overload def lower(self: LiteralString) -> LiteralString: ... @overload - def lower(self) -> str: ... + def lower(self) -> str: ... # type: ignore[misc] @overload def lstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... @overload - def lstrip(self, __chars: str | None = ...) -> str: ... + def lstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc] @overload def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... @overload - def partition(self, __sep: str) -> tuple[str, str, str]: ... + def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc] @overload def replace(self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...) -> LiteralString: ... @overload - def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... + def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 9): @overload def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ... @overload - def removeprefix(self, __prefix: str) -> str: ... + def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc] @overload def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ... @overload - def removesuffix(self, __suffix: str) -> str: ... + def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc] def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ... @overload def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ... @overload - def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... + def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc] @overload def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ... @overload - def rpartition(self, __sep: str) -> tuple[str, str, str]: ... + def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc] @overload def rsplit(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... @overload - def rsplit(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + def rsplit(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... # type: ignore[misc] @overload def rstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... @overload - def rstrip(self, __chars: str | None = ...) -> str: ... + def rstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc] @overload def split(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ... @overload - def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... + def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... # type: ignore[misc] @overload def splitlines(self: LiteralString, keepends: bool = ...) -> list[LiteralString]: ... @overload - def splitlines(self, keepends: bool = ...) -> list[str]: ... + def splitlines(self, keepends: bool = ...) -> list[str]: ... # type: ignore[misc] def startswith( self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ... ) -> bool: ... @overload def strip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ... @overload - def strip(self, __chars: str | None = ...) -> str: ... + def strip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc] @overload def swapcase(self: LiteralString) -> LiteralString: ... @overload - def swapcase(self) -> str: ... + def swapcase(self) -> str: ... # type: ignore[misc] @overload def title(self: LiteralString) -> LiteralString: ... @overload - def title(self) -> str: ... + def title(self) -> str: ... # type: ignore[misc] def translate(self, __table: Mapping[int, int | str | None] | Sequence[int | str | None]) -> str: ... @overload def upper(self: LiteralString) -> LiteralString: ... @overload - def upper(self) -> str: ... + def upper(self) -> str: ... # type: ignore[misc] @overload def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ... @overload - def zfill(self, __width: SupportsIndex) -> str: ... + def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc] @staticmethod @overload def maketrans(__x: dict[int, _T] | dict[str, _T] | dict[str | int, _T]) -> dict[int, _T]: ... @@ -536,7 +536,7 @@ class str(Sequence[str]): @overload def __add__(self: LiteralString, __s: LiteralString) -> LiteralString: ... @overload - def __add__(self, __s: str) -> str: ... + def __add__(self, __s: str) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ def __contains__(self, __o: str) -> bool: ... # type: ignore[override] def __eq__(self, __x: object) -> bool: ... @@ -547,20 +547,23 @@ class str(Sequence[str]): @overload def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... @overload - def __iter__(self) -> Iterator[str]: ... + def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] def __le__(self, __x: str) -> bool: ... def __len__(self) -> int: ... def __lt__(self, __x: str) -> bool: ... @overload def __mod__(self: LiteralString, __x: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ... @overload - def __mod__(self, __x: Any) -> str: ... + def __mod__(self, __x: Any) -> str: ... # type: ignore[misc] @overload def __mul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ... @overload - def __mul__(self, __n: SupportsIndex) -> str: ... + def __mul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc] def __ne__(self, __x: object) -> bool: ... - def __rmul__(self, n: SupportsIndex) -> str: ... + @overload + def __rmul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ... + @overload + def __rmul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... class bytes(ByteString):