Skip to content

Commit d0b4c40

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@51e18a8
1 parent d528bf2 commit d0b4c40

File tree

6 files changed

+116
-23
lines changed

6 files changed

+116
-23
lines changed

mypy/typeshed/stdlib/asyncio/transports.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SubprocessTransport(BaseTransport):
3939
def get_pid(self) -> int: ...
4040
def get_returncode(self) -> int | None: ...
4141
def get_pipe_transport(self, fd: int) -> BaseTransport | None: ...
42-
def send_signal(self, signal: int) -> int: ...
42+
def send_signal(self, signal: int) -> None: ...
4343
def terminate(self) -> None: ...
4444
def kill(self) -> None: ...
4545

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ from typing import ( # noqa: Y027
5555
overload,
5656
type_check_only,
5757
)
58-
from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard, final
58+
from typing_extensions import Literal, LiteralString, SupportsIndex, TypeAlias, TypeGuard, final
5959

6060
if sys.version_info >= (3, 9):
6161
from types import GenericAlias
@@ -414,20 +414,38 @@ class str(Sequence[str]):
414414
def __new__(cls: type[Self], object: object = ...) -> Self: ...
415415
@overload
416416
def __new__(cls: type[Self], object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
417+
@overload
418+
def capitalize(self: LiteralString) -> LiteralString: ...
419+
@overload
417420
def capitalize(self) -> str: ... # type: ignore[misc]
421+
@overload
422+
def casefold(self: LiteralString) -> LiteralString: ...
423+
@overload
418424
def casefold(self) -> str: ... # type: ignore[misc]
425+
@overload
426+
def center(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
427+
@overload
419428
def center(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
420429
def count(self, x: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
421430
def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ...
422431
def endswith(
423432
self, __suffix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
424433
) -> bool: ...
425434
if sys.version_info >= (3, 8):
435+
@overload
436+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = ...) -> LiteralString: ...
437+
@overload
426438
def expandtabs(self, tabsize: SupportsIndex = ...) -> str: ... # type: ignore[misc]
427439
else:
440+
@overload
441+
def expandtabs(self: LiteralString, tabsize: int = ...) -> LiteralString: ...
442+
@overload
428443
def expandtabs(self, tabsize: int = ...) -> str: ... # type: ignore[misc]
429444

430445
def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
446+
@overload
447+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
448+
@overload
431449
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore[misc]
432450
def format_map(self, map: _FormatMapMapping) -> str: ...
433451
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
@@ -443,53 +461,127 @@ class str(Sequence[str]):
443461
def isspace(self) -> bool: ...
444462
def istitle(self) -> bool: ...
445463
def isupper(self) -> bool: ...
464+
@overload
465+
def join(self: LiteralString, __iterable: Iterable[LiteralString]) -> LiteralString: ...
466+
@overload
446467
def join(self, __iterable: Iterable[str]) -> str: ... # type: ignore[misc]
468+
@overload
469+
def ljust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
470+
@overload
447471
def ljust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
472+
@overload
473+
def lower(self: LiteralString) -> LiteralString: ...
474+
@overload
448475
def lower(self) -> str: ... # type: ignore[misc]
476+
@overload
477+
def lstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
478+
@overload
449479
def lstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
480+
@overload
481+
def partition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
482+
@overload
450483
def partition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
484+
@overload
485+
def replace(
486+
self: LiteralString, __old: LiteralString, __new: LiteralString, __count: SupportsIndex = ...
487+
) -> LiteralString: ...
488+
@overload
451489
def replace(self, __old: str, __new: str, __count: SupportsIndex = ...) -> str: ... # type: ignore[misc]
452490
if sys.version_info >= (3, 9):
491+
@overload
492+
def removeprefix(self: LiteralString, __prefix: LiteralString) -> LiteralString: ...
493+
@overload
453494
def removeprefix(self, __prefix: str) -> str: ... # type: ignore[misc]
495+
@overload
496+
def removesuffix(self: LiteralString, __suffix: LiteralString) -> LiteralString: ...
497+
@overload
454498
def removesuffix(self, __suffix: str) -> str: ... # type: ignore[misc]
455499

456500
def rfind(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
457501
def rindex(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
502+
@overload
503+
def rjust(self: LiteralString, __width: SupportsIndex, __fillchar: LiteralString = ...) -> LiteralString: ...
504+
@overload
458505
def rjust(self, __width: SupportsIndex, __fillchar: str = ...) -> str: ... # type: ignore[misc]
506+
@overload
507+
def rpartition(self: LiteralString, __sep: LiteralString) -> tuple[LiteralString, LiteralString, LiteralString]: ...
508+
@overload
459509
def rpartition(self, __sep: str) -> tuple[str, str, str]: ... # type: ignore[misc]
510+
@overload
511+
def rsplit(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ...
512+
@overload
460513
def rsplit(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... # type: ignore[misc]
514+
@overload
515+
def rstrip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
516+
@overload
461517
def rstrip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
518+
@overload
519+
def split(self: LiteralString, sep: LiteralString | None = ..., maxsplit: SupportsIndex = ...) -> list[LiteralString]: ...
520+
@overload
462521
def split(self, sep: str | None = ..., maxsplit: SupportsIndex = ...) -> list[str]: ... # type: ignore[misc]
522+
@overload
523+
def splitlines(self: LiteralString, keepends: bool = ...) -> list[LiteralString]: ...
524+
@overload
463525
def splitlines(self, keepends: bool = ...) -> list[str]: ... # type: ignore[misc]
464526
def startswith(
465527
self, __prefix: str | tuple[str, ...], __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...
466528
) -> bool: ...
529+
@overload
530+
def strip(self: LiteralString, __chars: LiteralString | None = ...) -> LiteralString: ...
531+
@overload
467532
def strip(self, __chars: str | None = ...) -> str: ... # type: ignore[misc]
533+
@overload
534+
def swapcase(self: LiteralString) -> LiteralString: ...
535+
@overload
468536
def swapcase(self) -> str: ... # type: ignore[misc]
537+
@overload
538+
def title(self: LiteralString) -> LiteralString: ...
539+
@overload
469540
def title(self) -> str: ... # type: ignore[misc]
470541
def translate(self, __table: _TranslateTable) -> str: ...
542+
@overload
543+
def upper(self: LiteralString) -> LiteralString: ...
544+
@overload
471545
def upper(self) -> str: ... # type: ignore[misc]
546+
@overload
547+
def zfill(self: LiteralString, __width: SupportsIndex) -> LiteralString: ...
548+
@overload
472549
def zfill(self, __width: SupportsIndex) -> str: ... # type: ignore[misc]
473550
@staticmethod
474551
@overload
475552
def maketrans(__x: dict[int, _T] | dict[str, _T] | dict[str | int, _T]) -> dict[int, _T]: ...
476553
@staticmethod
477554
@overload
478555
def maketrans(__x: str, __y: str, __z: str | None = ...) -> dict[int, int | None]: ...
556+
@overload
557+
def __add__(self: LiteralString, __s: LiteralString) -> LiteralString: ...
558+
@overload
479559
def __add__(self, __s: str) -> str: ... # type: ignore[misc]
480560
# Incompatible with Sequence.__contains__
481561
def __contains__(self, __o: str) -> bool: ... # type: ignore[override]
482562
def __eq__(self, __x: object) -> bool: ...
483563
def __ge__(self, __x: str) -> bool: ...
484564
def __getitem__(self, __i: SupportsIndex | slice) -> str: ...
485565
def __gt__(self, __x: str) -> bool: ...
566+
@overload
567+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
568+
@overload
486569
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
487570
def __le__(self, __x: str) -> bool: ...
488571
def __len__(self) -> int: ...
489572
def __lt__(self, __x: str) -> bool: ...
573+
@overload
574+
def __mod__(self: LiteralString, __x: LiteralString | tuple[LiteralString, ...]) -> LiteralString: ...
575+
@overload
490576
def __mod__(self, __x: Any) -> str: ... # type: ignore[misc]
577+
@overload
578+
def __mul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ...
579+
@overload
491580
def __mul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc]
492581
def __ne__(self, __x: object) -> bool: ...
582+
@overload
583+
def __rmul__(self: LiteralString, __n: SupportsIndex) -> LiteralString: ...
584+
@overload
493585
def __rmul__(self, __n: SupportsIndex) -> str: ... # type: ignore[misc]
494586
def __getnewargs__(self) -> tuple[str]: ...
495587

mypy/typeshed/stdlib/ctypes/__init__.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,10 @@ class _Pointer(Generic[_CT], _PointerLike, _CData):
165165
@overload
166166
def __init__(self, arg: _CT) -> None: ...
167167
@overload
168-
def __getitem__(self, __i: int) -> _CT: ...
169-
@overload
170-
def __getitem__(self, __s: slice) -> list[_CT]: ...
171-
@overload
172-
def __setitem__(self, __i: int, __o: _CT) -> None: ...
168+
def __getitem__(self, __i: int) -> Any: ...
173169
@overload
174-
def __setitem__(self, __s: slice, __o: Iterable[_CT]) -> None: ...
170+
def __getitem__(self, __s: slice) -> list[Any]: ...
171+
def __setitem__(self, __i: int, __o: Any) -> None: ...
175172

176173
def pointer(__arg: _CT) -> _Pointer[_CT]: ...
177174
def resize(obj: _CData, size: int) -> None: ...

mypy/typeshed/stdlib/pydoc.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from collections.abc import Callable, Container, Mapping, MutableMapping
66
from reprlib import Repr
77
from types import MethodType, ModuleType, TracebackType
88
from typing import IO, Any, AnyStr, NoReturn, TypeVar
9+
from typing_extensions import TypeGuard
910

1011
__all__ = ["help"]
1112

@@ -231,5 +232,5 @@ class ModuleScanner:
231232
) -> None: ...
232233

233234
def apropos(key: str) -> None: ...
234-
def ispath(x: Any) -> bool: ...
235+
def ispath(x: object) -> TypeGuard[str]: ...
235236
def cli() -> None: ...

mypy/typeshed/stdlib/subprocess.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,8 @@ class TimeoutExpired(SubprocessError):
18281828
timeout: float
18291829
# morally: _TXT | None
18301830
output: Any
1831-
stdout: Any
1832-
stderr: Any
1831+
stdout: bytes | None
1832+
stderr: bytes | None
18331833

18341834
class CalledProcessError(SubprocessError):
18351835
returncode: int

mypy/typeshed/stdlib/urllib/parse.pyi

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
from collections.abc import Callable, Mapping, Sequence
33
from typing import Any, AnyStr, Generic, NamedTuple, overload
4-
from typing_extensions import TypeAlias
54

65
if sys.version_info >= (3, 9):
76
from types import GenericAlias
@@ -30,8 +29,6 @@ __all__ = [
3029
"SplitResultBytes",
3130
]
3231

33-
_Str: TypeAlias = bytes | str
34-
3532
uses_relative: list[str]
3633
uses_netloc: list[str]
3734
uses_params: list[str]
@@ -135,16 +132,22 @@ def parse_qsl(
135132
separator: str = ...,
136133
) -> list[tuple[AnyStr, AnyStr]]: ...
137134
@overload
138-
def quote(string: str, safe: _Str = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
135+
def quote(string: str, safe: str | bytes = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
139136
@overload
140-
def quote(string: bytes, safe: _Str = ...) -> str: ...
141-
def quote_from_bytes(bs: bytes, safe: _Str = ...) -> str: ...
137+
def quote(string: bytes, safe: str | bytes = ...) -> str: ...
138+
def quote_from_bytes(bs: bytes, safe: str | bytes = ...) -> str: ...
142139
@overload
143-
def quote_plus(string: str, safe: _Str = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
140+
def quote_plus(string: str, safe: str | bytes = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
144141
@overload
145-
def quote_plus(string: bytes, safe: _Str = ...) -> str: ...
146-
def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ...
147-
def unquote_to_bytes(string: _Str) -> bytes: ...
142+
def quote_plus(string: bytes, safe: str | bytes = ...) -> str: ...
143+
144+
if sys.version_info >= (3, 9):
145+
def unquote(string: str | bytes, encoding: str = ..., errors: str = ...) -> str: ...
146+
147+
else:
148+
def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ...
149+
150+
def unquote_to_bytes(string: str | bytes) -> bytes: ...
148151
def unquote_plus(string: str, encoding: str = ..., errors: str = ...) -> str: ...
149152
@overload
150153
def urldefrag(url: str) -> DefragResult: ...
@@ -153,10 +156,10 @@ def urldefrag(url: bytes | None) -> DefragResultBytes: ...
153156
def urlencode(
154157
query: Mapping[Any, Any] | Mapping[Any, Sequence[Any]] | Sequence[tuple[Any, Any]] | Sequence[tuple[Any, Sequence[Any]]],
155158
doseq: bool = ...,
156-
safe: _Str = ...,
159+
safe: str | bytes = ...,
157160
encoding: str = ...,
158161
errors: str = ...,
159-
quote_via: Callable[[AnyStr, _Str, str, str], str] = ...,
162+
quote_via: Callable[[AnyStr, str | bytes, str, str], str] = ...,
160163
) -> str: ...
161164
def urljoin(base: AnyStr, url: AnyStr | None, allow_fragments: bool = ...) -> AnyStr: ...
162165
@overload

0 commit comments

Comments
 (0)