Use SupportsIndex where applicable for 5 classes (#5694)

Use `SupportsIndex` where applicable:

* `str`
* `bytes`
* `bytearray`
* `memoryview`
* `markupsafe.Markup`
This commit is contained in:
Bas van Beek
2021-06-26 18:05:40 +02:00
committed by GitHub
parent c522e8e53c
commit 50f5858a56
2 changed files with 83 additions and 70 deletions
+14 -10
View File
@@ -1,6 +1,7 @@
import string
import sys
from typing import Any, Callable, Iterable, Mapping, Optional, Sequence, Text, Tuple, Union
from typing_extensions import SupportsIndex
from markupsafe._compat import text_type
from markupsafe._native import escape as escape, escape_silent as escape_silent, soft_unicode as soft_unicode
@@ -10,12 +11,12 @@ class Markup(text_type):
def __html__(self) -> Markup: ...
def __add__(self, other: text_type) -> Markup: ...
def __radd__(self, other: text_type) -> Markup: ...
def __mul__(self, num: int) -> Markup: ...
def __rmul__(self, num: int) -> Markup: ...
def __mul__(self, num: int) -> Markup: ... # type: ignore
def __rmul__(self, num: int) -> Markup: ... # type: ignore
def __mod__(self, *args: Any) -> Markup: ...
def join(self, seq: Iterable[text_type]) -> Markup: ...
def split(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> list[Markup]: ... # type: ignore
def rsplit(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> list[Markup]: ... # type: ignore
def split(self, sep: Optional[text_type] = ..., maxsplit: SupportsIndex = ...) -> list[Markup]: ... # type: ignore
def rsplit(self, sep: Optional[text_type] = ..., maxsplit: SupportsIndex = ...) -> list[Markup]: ... # type: ignore
def splitlines(self, keepends: bool = ...) -> list[Markup]: ... # type: ignore
def unescape(self) -> Text: ...
def striptags(self) -> Text: ...
@@ -32,18 +33,21 @@ class Markup(text_type):
def lower(self) -> Markup: ...
def upper(self) -> Markup: ...
def swapcase(self) -> Markup: ...
def replace(self, old: text_type, new: text_type, count: int = ...) -> Markup: ...
def ljust(self, width: int, fillchar: text_type = ...) -> Markup: ...
def rjust(self, width: int, fillchar: text_type = ...) -> Markup: ...
def replace(self, old: text_type, new: text_type, count: SupportsIndex = ...) -> Markup: ...
def ljust(self, width: SupportsIndex, fillchar: text_type = ...) -> Markup: ...
def rjust(self, width: SupportsIndex, fillchar: text_type = ...) -> Markup: ...
def lstrip(self, chars: Optional[text_type] = ...) -> Markup: ...
def rstrip(self, chars: Optional[text_type] = ...) -> Markup: ...
def strip(self, chars: Optional[text_type] = ...) -> Markup: ...
def center(self, width: int, fillchar: text_type = ...) -> Markup: ...
def zfill(self, width: int) -> Markup: ...
def center(self, width: SupportsIndex, fillchar: text_type = ...) -> Markup: ...
def zfill(self, width: SupportsIndex) -> Markup: ...
def translate(
self, table: Union[Mapping[int, Union[int, text_type, None]], Sequence[Union[int, text_type, None]]]
) -> Markup: ...
def expandtabs(self, tabsize: int = ...) -> Markup: ...
if sys.version_info >= (3, 8):
def expandtabs(self, tabsize: SupportsIndex = ...) -> Markup: ...
else:
def expandtabs(self, tabsize: int = ...) -> Markup: ...
class EscapeFormatter(string.Formatter):
escape: Callable[[text_type], Markup]