1#!/usr/bin/env python3
2"""
3Adapated from typeshed, this is a full protocol of the stdlib `str`.
4
5"""
6# mypy: disable-error-code="misc"
7# ruff: noqa: UP049, A002, ANN401, FBT001, FBT002
8# Imports:
9from __future__ import annotations
10
11# ##-- stdlib imports
12import datetime
13import enum
14import functools as ftz
15import itertools as itz
16import logging as logmod
17import pathlib as pl
18import re
19import time
20import types
21import collections
22import contextlib
23import hashlib
24from copy import deepcopy
25from uuid import UUID, uuid1
26from weakref import ref
27import atexit # for @atexit.register
28import faulthandler
29# ##-- end stdlib imports
30
31# ##-- types
32# isort: off
33import abc
34import collections.abc
35from typing import TYPE_CHECKING, cast, assert_type, assert_never
36from typing import Generic, NewType, Never
37# Protocols:
38from typing import Protocol, runtime_checkable
39# Typing Decorators:
40from typing import no_type_check, final, override, overload
41
42if TYPE_CHECKING:
43 from jgdv import Maybe
44 from typing import Final
45 from typing import ClassVar, Any, LiteralString
46 from typing import Self, Literal
47 from typing import TypeGuard
48 from collections.abc import Iterable, Iterator, Callable, Generator
49 from collections.abc import Mapping, MutableMapping, Hashable
50
51##--|
52
53type ReadableBuffer = Any
54type SupportsIndex = Any
55type _FormatMapMapping = Any
56type _TranslateTable = Any
57# isort: on
58# ##-- end types
59
60##-- logging
61logging = logmod.getLogger(__name__)
62##-- end logging
63
64# Vars:
65
66# Body:
67
[docs]
68class String_p(Protocol):
69
70 ##--| Overloaded methods
71
72 @overload
73 @staticmethod
74 def maketrans[_T](x:dict[str|int, _T], /) -> dict[int, _T]:...
75
76 @overload
77 @staticmethod
78 def maketrans(x:str, y:str, /) -> dict[int, int]:...
79
[docs]
80 @overload
81 @staticmethod
82 def maketrans(x:str, y:str, z:str, /) -> dict[int, Maybe[int]]:...
83
84 @overload
85 def __add__(self:LiteralString, value:LiteralString, /) -> LiteralString:...
86 @overload
87 def __add__(self, value:str, /) -> str:...
88
89 @overload
90 def __getitem__(self:LiteralString, key:SupportsIndex|slice, /) -> LiteralString:...
91
92 @overload
93 def __getitem__(self, key:SupportsIndex|slice, /) -> str:...
94
95 ##--| Ctor:
96
97 def __new__(cls, object:ReadableBuffer, encoding:str=..., errors:str=...) -> Self:...
98
99 ##--| Overrides
100
101 @override
102 def __eq__(self, value:object, /) -> bool:...
103
104 @override
105 def __hash__(self) -> int:...
106
107 @override
108 def __ne__(self, value:object, /) -> bool:...
109
110
111 ##--| Dunders
112 def __contains__(self, key:str, /) -> bool:...
113
114 def __ge__(self, value:str, /) -> bool:...
115
116 def __gt__(self, value:str, /) -> bool:...
117
118 def __iter__(self) -> Iterator[str]:...
119
120 def __le__(self, value:str, /) -> bool:...
121
122 def __len__(self) -> int:...
123
124 def __lt__(self, value:str, /) -> bool:...
125
126 def __mod__(self, value:Any, /) -> str:...
127
128 def __mul__(self, value:SupportsIndex, /) -> str:...
129
130 def __rmul__(self, value:SupportsIndex, /) -> str:...
131
132 def __getnewargs__(self) -> tuple[str]:...
133 ##--| rest
134
[docs]
135 def capitalize(self) -> str:...
136
[docs]
137 def casefold(self) -> str:...
138
[docs]
139 def center(self, width:SupportsIndex, fillchar:str=" ", /) -> str:...
140
[docs]
141 def count(self, sub:str, start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> int:...
142
[docs]
143 def encode(self, encoding:str="utf-8", errors:str="strict") -> bytes:...
144
[docs]
145 def endswith(self, suffix:str|tuple[str, ...], start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=...) -> bool:...
146
[docs]
147 def expandtabs(self, tabsize:SupportsIndex=8) -> str:...
148
[docs]
149 def find(self, sub:str, start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> int:...
150
152
154
[docs]
155 def index(self, sub:str, start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> int:...
156
[docs]
157 def isalnum(self) -> bool:...
158
[docs]
159 def isalpha(self) -> bool:...
160
[docs]
161 def isascii(self) -> bool:...
162
[docs]
163 def isdecimal(self) -> bool:...
164
[docs]
165 def isdigit(self) -> bool:...
166
[docs]
167 def isidentifier(self) -> bool:...
168
[docs]
169 def islower(self) -> bool:...
170
[docs]
171 def isnumeric(self) -> bool:...
172
[docs]
173 def isprintable(self) -> bool:...
174
[docs]
175 def isspace(self) -> bool:...
176
[docs]
177 def istitle(self) -> bool:...
178
[docs]
179 def isupper(self) -> bool:...
180
[docs]
181 def join(self, iterable:Iterable[str], /) -> str:...
182
[docs]
183 def ljust(self, width:SupportsIndex, fillchar:str=" ", /) -> str:...
184
[docs]
185 def lower(self) -> str:...
186
[docs]
187 def lstrip(self, chars:Maybe[str]=None, /) -> str:...
188
[docs]
189 def partition(self, sep:str, /) -> tuple[str, str, str]:...
190
[docs]
191 def replace(self, old:LiteralString, new:LiteralString, /, count:SupportsIndex=-1) -> LiteralString:...
192
[docs]
193 def removeprefix(self, prefix:str, /) -> str:...
194
[docs]
195 def removesuffix(self, suffix:str, /) -> str:...
196
[docs]
197 def rfind(self, sub:str, start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> int:...
198
[docs]
199 def rindex(self, sub:str, start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> int:...
200
[docs]
201 def rjust(self, width:SupportsIndex, fillchar:str=" ", /) -> str:...
202
[docs]
203 def rpartition(self, sep:str, /) -> tuple[str, str, str]:...
204
[docs]
205 def rsplit(self, sep:Maybe[str]=None, maxsplit:SupportsIndex=-1) -> list[str]:...
206
[docs]
207 def rstrip(self, chars:Maybe[str]=None, /) -> str:...
208
[docs]
209 def split(self, sep:Maybe[str]=None, maxsplit:SupportsIndex=-1) -> list[str]:...
210
[docs]
211 def splitlines(self, keepends:bool=False) -> list[str]:...
212
[docs]
213 def startswith(self, prefix:str|tuple[str, ...], start:Maybe[SupportsIndex]=..., end:Maybe[SupportsIndex]=..., /) -> bool:...
214
[docs]
215 def strip(self, chars:Maybe[str]=None, /) -> str:...
216
[docs]
217 def swapcase(self) -> str:...
218
[docs]
219 def title(self) -> str:...
220
[docs]
221 def translate(self, table:_TranslateTable, /) -> str:...
222
[docs]
223 def upper(self) -> str:...
224
[docs]
225 def zfill(self, width:SupportsIndex, /) -> str:...
226