1- From b3021cdc4b4c2cf547c5bc2d1d21a5a00ffea001 Mon Sep 17 00:00:00 2001
1+ From 83cf9b2dcc569149510c3a9118b9a7dc44144232 Mon Sep 17 00:00:00 2001
22From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
33Date: Mon, 26 Sep 2022 12:55:07 -0700
44Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
55
66---
7- mypy/typeshed/stdlib/builtins.pyi | 98 -- -----------------------------
8- 1 file changed, 98 deletions(-)
7+ mypy/typeshed/stdlib/builtins.pyi | 127 + -----------------------------
8+ 1 file changed, 1 insertion(+), 126 deletions(-)
99
1010diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11- index efc51fe25..8600a372b 100644
11+ index 0fe6d9a69..1808e28e2 100644
1212--- a/mypy/typeshed/stdlib/builtins.pyi
1313+++ b/mypy/typeshed/stdlib/builtins.pyi
14- @@ -64,7 +64,6 @@ from typing import ( # noqa: Y022,UP035
15- from typing_extensions import ( # noqa: Y023
16- Concatenate,
17- Literal,
18- - LiteralString,
19- ParamSpec,
20- Self,
21- TypeAlias,
22- @@ -482,31 +481,16 @@ class str(Sequence[str]):
14+ @@ -65,7 +65,7 @@ from typing import ( # noqa: Y022,UP035
15+ )
16+
17+ # we can't import `Literal` from typing or mypy crashes: see #11247
18+ - from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035
19+ + from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035
20+
21+ if sys.version_info >= (3, 14):
22+ from _typeshed import AnnotateFunc
23+ @@ -489,20 +489,8 @@ class str(Sequence[str]):
2324 def __new__(cls, object: object = "") -> Self: ...
2425 @overload
2526 def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ...
27+ -
2628- @overload
2729- def capitalize(self: LiteralString) -> LiteralString: ...
2830- @overload
2931 def capitalize(self) -> str: ... # type: ignore[misc]
32+ -
3033- @overload
3134- def casefold(self: LiteralString) -> LiteralString: ...
3235- @overload
3336 def casefold(self) -> str: ... # type: ignore[misc]
37+ -
3438- @overload
3539- def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
3640- @overload
3741 def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
42+
3843 def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
39- def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
44+ @@ -510,17 +498,9 @@ class str(Sequence[str]):
4045 def endswith(
4146 self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
4247 ) -> bool: ...
48+ -
4349- @overload
4450- def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
4551- @overload
4652 def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
53+
4754 def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
55+ -
4856- @overload
4957- def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
5058- @overload
5159 def format(self, *args: object, **kwargs: object) -> str: ...
60+
5261 def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
53- def index(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
54- @@ -522,98 +506,34 @@ class str(Sequence[str]):
62+ @@ -537,119 +517,38 @@ class str(Sequence[str]):
5563 def isspace(self) -> bool: ...
5664 def istitle(self) -> bool: ...
5765 def isupper(self) -> bool: ...
66+ -
5867- @overload
5968- def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
6069- @overload
6170 def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
71+ -
6272- @overload
6373- def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
6474- @overload
6575 def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
76+ -
6677- @overload
6778- def lower(self: LiteralString) -> LiteralString: ...
6879- @overload
6980 def lower(self) -> str: ... # type: ignore[misc]
81+ -
7082- @overload
7183- def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
7284- @overload
7385 def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
86+ -
7487- @overload
7588- def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
7689- @overload
7790 def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
91+
7892 if sys.version_info >= (3, 13):
7993- @overload
8094- def replace(
@@ -94,102 +108,127 @@ index efc51fe25..8600a372b 100644
94108- def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
95109- @overload
96110 def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
111+ -
97112- @overload
98113- def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
99114- @overload
100115 def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
116+
101117 def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
102118 def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ...
119+ -
103120- @overload
104121- def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
105122- @overload
106123 def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
124+ -
107125- @overload
108126- def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
109127- @overload
110128 def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
129+ -
111130- @overload
112131- def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
113132- @overload
114133 def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
134+ -
115135- @overload
116136- def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
117137- @overload
118138 def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
139+ -
119140- @overload
120141- def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
121142- @overload
122143 def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
144+ -
123145- @overload
124146- def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
125147- @overload
126148 def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
149+
127150 def startswith(
128151 self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /
129152 ) -> bool: ...
153+ -
130154- @overload
131155- def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
132156- @overload
133157 def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
158+ -
134159- @overload
135160- def swapcase(self: LiteralString) -> LiteralString: ...
136161- @overload
137162 def swapcase(self) -> str: ... # type: ignore[misc]
163+ -
138164- @overload
139165- def title(self: LiteralString) -> LiteralString: ...
140166- @overload
141167 def title(self) -> str: ... # type: ignore[misc]
168+
142169 def translate(self, table: _TranslateTable, /) -> str: ...
170+ -
143171- @overload
144172- def upper(self: LiteralString) -> LiteralString: ...
145173- @overload
146174 def upper(self) -> str: ... # type: ignore[misc]
175+ -
147176- @overload
148177- def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
149178- @overload
150179 def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151- @staticmethod
152- @overload
153- @@ -624,39 +544,21 @@ class str(Sequence[str]):
180+
181+ if sys.version_info >= (3, 15):
182+ @@ -677,49 +576,25 @@ class str(Sequence[str]):
154183 @staticmethod
155184 @overload
156185 def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
186+ -
157187- @overload
158188- def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
159189- @overload
160190 def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
191+
161192 # Incompatible with Sequence.__contains__
162193 def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
163194 def __eq__(self, value: object, /) -> bool: ...
164195 def __ge__(self, value: str, /) -> bool: ...
196+ -
165197- @overload
166198- def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ...
167199- @overload
168200 def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc]
201+
169202 def __gt__(self, value: str, /) -> bool: ...
170203 def __hash__(self) -> int: ...
204+ -
171205- @overload
172206- def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
173207- @overload
174208 def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
209+
175210 def __le__(self, value: str, /) -> bool: ...
176211 def __len__(self) -> int: ...
177212 def __lt__(self, value: str, /) -> bool: ...
213+ -
178214- @overload
179215- def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
180216- @overload
181217 def __mod__(self, value: Any, /) -> str: ...
218+ -
182219- @overload
183220- def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
184221- @overload
185222 def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
223+
186224 def __ne__(self, value: object, /) -> bool: ...
225+ -
187226- @overload
188227- def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
189228- @overload
190229 def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
230+
191231 def __getnewargs__(self) -> tuple[str]: ...
192- def __format__(self, format_spec: str, /) -> str: ...
193232- -
194- 2.52 .0
233+ 2.54 .0
195234
0 commit comments