Skip to content

Commit fc52950

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@0d100b9
1 parent 8412d1d commit fc52950

File tree

12 files changed

+177
-63
lines changed

12 files changed

+177
-63
lines changed

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
55
from types import FrameType, GenericAlias
66
from typing import Any, Literal, TextIO, TypeVar
@@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True)
1111
_TaskYieldType: TypeAlias = Future[object] | None
1212

1313
@disjoint_base
14-
class Future(Awaitable[_T], Iterable[_T]):
14+
class Future(Awaitable[_T]):
1515
_state: str
1616
@property
1717
def _exception(self) -> BaseException | None: ...

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
294294
def _type_(self) -> type[_CT]: ...
295295
@_type_.setter
296296
def _type_(self, value: type[_CT]) -> None: ...
297-
raw: bytes # Note: only available if _CT == c_char
297+
# Note: only available if _CT == c_char
298+
@property
299+
def raw(self) -> bytes: ...
300+
@raw.setter
301+
def raw(self, value: ReadableBuffer) -> None: ...
298302
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
299303
# TODO: These methods cannot be annotated correctly at the moment.
300304
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/argparse.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sys
22
from _typeshed import SupportsWrite, sentinel
33
from collections.abc import Callable, Generator, Iterable, Sequence
44
from re import Pattern
5-
from typing import IO, Any, ClassVar, Final, Generic, NewType, NoReturn, Protocol, TypeVar, overload, type_check_only
5+
from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload, type_check_only
66
from typing_extensions import Self, TypeAlias, deprecated
77

88
__all__ = [
@@ -36,9 +36,7 @@ ONE_OR_MORE: Final = "+"
3636
OPTIONAL: Final = "?"
3737
PARSER: Final = "A..."
3838
REMAINDER: Final = "..."
39-
_SUPPRESS_T = NewType("_SUPPRESS_T", str)
40-
SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is
41-
# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy
39+
SUPPRESS: Final = "==SUPPRESS=="
4240
ZERO_OR_MORE: Final = "*"
4341
_UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented
4442

@@ -81,7 +79,7 @@ class _ActionsContainer:
8179
# more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="],
8280
# but using this would make it hard to annotate callers that don't use a
8381
# literal argument and for subclasses to override this method.
84-
nargs: int | str | _SUPPRESS_T | None = None,
82+
nargs: int | str | None = None,
8583
const: Any = ...,
8684
default: Any = ...,
8785
type: _ActionType = ...,

mypy/typeshed/stdlib/asyncio/events.pyi

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,25 @@ class AbstractEventLoop:
602602
@abstractmethod
603603
async def shutdown_default_executor(self) -> None: ...
604604

605-
# This class does not exist at runtime, but stubtest complains if it's marked as
606-
# @type_check_only because it has an alias that does exist at runtime. See mypy#19568.
607-
# @type_check_only
608-
class _AbstractEventLoopPolicy:
609-
@abstractmethod
610-
def get_event_loop(self) -> AbstractEventLoop: ...
611-
@abstractmethod
612-
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
613-
@abstractmethod
614-
def new_event_loop(self) -> AbstractEventLoop: ...
615-
# Child processes handling (Unix only).
616-
if sys.version_info < (3, 14):
605+
if sys.version_info >= (3, 14):
606+
class _AbstractEventLoopPolicy:
607+
@abstractmethod
608+
def get_event_loop(self) -> AbstractEventLoop: ...
609+
@abstractmethod
610+
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
611+
@abstractmethod
612+
def new_event_loop(self) -> AbstractEventLoop: ...
613+
614+
else:
615+
@type_check_only
616+
class _AbstractEventLoopPolicy:
617+
@abstractmethod
618+
def get_event_loop(self) -> AbstractEventLoop: ...
619+
@abstractmethod
620+
def set_event_loop(self, loop: AbstractEventLoop | None) -> None: ...
621+
@abstractmethod
622+
def new_event_loop(self) -> AbstractEventLoop: ...
623+
# Child processes handling (Unix only).
617624
if sys.version_info >= (3, 12):
618625
@abstractmethod
619626
@deprecated("Deprecated since Python 3.12; removed in Python 3.14.")
@@ -627,7 +634,6 @@ class _AbstractEventLoopPolicy:
627634
@abstractmethod
628635
def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ...
629636

630-
if sys.version_info < (3, 14):
631637
AbstractEventLoopPolicy = _AbstractEventLoopPolicy
632638

633639
if sys.version_info >= (3, 14):

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 107 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ from typing import ( # noqa: Y022,UP035
6363
from typing_extensions import ( # noqa: Y023
6464
Concatenate,
6565
Literal,
66+
LiteralString,
6667
ParamSpec,
6768
Self,
6869
TypeAlias,
@@ -477,16 +478,31 @@ class str(Sequence[str]):
477478
def __new__(cls, object: object = ...) -> Self: ...
478479
@overload
479480
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
481+
@overload
482+
def capitalize(self: LiteralString) -> LiteralString: ...
483+
@overload
480484
def capitalize(self) -> str: ... # type: ignore[misc]
485+
@overload
486+
def casefold(self: LiteralString) -> LiteralString: ...
487+
@overload
481488
def casefold(self) -> str: ... # type: ignore[misc]
489+
@overload
490+
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
491+
@overload
482492
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
483493
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
484494
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
485495
def endswith(
486496
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
487497
) -> bool: ...
498+
@overload
499+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
500+
@overload
488501
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
489502
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
503+
@overload
504+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
505+
@overload
490506
def format(self, *args: object, **kwargs: object) -> str: ...
491507
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
492508
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -502,34 +518,98 @@ class str(Sequence[str]):
502518
def isspace(self) -> bool: ...
503519
def istitle(self) -> bool: ...
504520
def isupper(self) -> bool: ...
521+
@overload
522+
def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
523+
@overload
505524
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
525+
@overload
526+
def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
527+
@overload
506528
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
529+
@overload
530+
def lower(self: LiteralString) -> LiteralString: ...
531+
@overload
507532
def lower(self) -> str: ... # type: ignore[misc]
533+
@overload
534+
def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
535+
@overload
508536
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
537+
@overload
538+
def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
539+
@overload
509540
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
510541
if sys.version_info >= (3, 13):
542+
@overload
543+
def replace(
544+
self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
545+
) -> LiteralString: ...
546+
@overload
511547
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
512548
else:
549+
@overload
550+
def replace(
551+
self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
552+
) -> LiteralString: ...
553+
@overload
513554
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
514555

556+
@overload
557+
def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
558+
@overload
515559
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
560+
@overload
561+
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
562+
@overload
516563
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
517564
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
518565
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
566+
@overload
567+
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
568+
@overload
519569
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
570+
@overload
571+
def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
572+
@overload
520573
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
574+
@overload
575+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
576+
@overload
521577
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
578+
@overload
579+
def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
580+
@overload
522581
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
582+
@overload
583+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
584+
@overload
523585
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
586+
@overload
587+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
588+
@overload
524589
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
525590
def startswith(
526591
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
527592
) -> bool: ...
593+
@overload
594+
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
595+
@overload
528596
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
597+
@overload
598+
def swapcase(self: LiteralString) -> LiteralString: ...
599+
@overload
529600
def swapcase(self) -> str: ... # type: ignore[misc]
601+
@overload
602+
def title(self: LiteralString) -> LiteralString: ...
603+
@overload
530604
def title(self) -> str: ... # type: ignore[misc]
531605
def translate(self, table: _TranslateTable, /) -> str: ...
606+
@overload
607+
def upper(self: LiteralString) -> LiteralString: ...
608+
@overload
532609
def upper(self) -> str: ... # type: ignore[misc]
610+
@overload
611+
def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
612+
@overload
533613
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
534614
@staticmethod
535615
@overload
@@ -540,21 +620,39 @@ class str(Sequence[str]):
540620
@staticmethod
541621
@overload
542622
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
623+
@overload
624+
def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
625+
@overload
543626
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
544627
# Incompatible with Sequence.__contains__
545628
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
546629
def __eq__(self, value: object, /) -> bool: ...
547630
def __ge__(self, value: str, /) -> bool: ...
548-
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
631+
@overload
632+
def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
633+
@overload
634+
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
549635
def __gt__(self, value: str, /) -> bool: ...
550636
def __hash__(self) -> int: ...
637+
@overload
638+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
639+
@overload
551640
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
552641
def __le__(self, value: str, /) -> bool: ...
553642
def __len__(self) -> int: ...
554643
def __lt__(self, value: str, /) -> bool: ...
644+
@overload
645+
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
646+
@overload
555647
def __mod__(self, value: Any, /) -> str: ...
648+
@overload
649+
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
650+
@overload
556651
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
557652
def __ne__(self, value: object, /) -> bool: ...
653+
@overload
654+
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
655+
@overload
558656
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
559657
def __getnewargs__(self) -> tuple[str]: ...
560658
def __format__(self, format_spec: str, /) -> str: ...
@@ -923,8 +1021,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
9231021

9241022
def indices(self, len: SupportsIndex, /) -> tuple[int, int, int]: ...
9251023

926-
# Making this a disjoint_base upsets pyright
927-
# @disjoint_base
1024+
@disjoint_base
9281025
class tuple(Sequence[_T_co]):
9291026
def __new__(cls, iterable: Iterable[_T_co] = ..., /) -> Self: ...
9301027
def __len__(self) -> int: ...
@@ -1209,7 +1306,7 @@ class frozenset(AbstractSet[_T_co]):
12091306
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
12101307

12111308
@disjoint_base
1212-
class enumerate(Iterator[tuple[int, _T]]):
1309+
class enumerate(Generic[_T]):
12131310
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
12141311
def __iter__(self) -> Self: ...
12151312
def __next__(self) -> tuple[int, _T]: ...
@@ -1266,10 +1363,8 @@ class property:
12661363
def __set__(self, instance: Any, value: Any, /) -> None: ...
12671364
def __delete__(self, instance: Any, /) -> None: ...
12681365

1269-
# This class does not exist at runtime, but stubtest complains if it's marked as
1270-
# @type_check_only because it has an alias that does exist at runtime. See mypy#19568.
1271-
# @type_check_only
12721366
@final
1367+
@type_check_only
12731368
class _NotImplementedType(Any):
12741369
__call__: None
12751370

@@ -1405,7 +1500,7 @@ else:
14051500
exit: _sitebuiltins.Quitter
14061501

14071502
@disjoint_base
1408-
class filter(Iterator[_T]):
1503+
class filter(Generic[_T]):
14091504
@overload
14101505
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
14111506
@overload
@@ -1469,7 +1564,7 @@ license: _sitebuiltins._Printer
14691564

14701565
def locals() -> dict[str, Any]: ...
14711566
@disjoint_base
1472-
class map(Iterator[_S]):
1567+
class map(Generic[_S]):
14731568
# 3.14 adds `strict` argument.
14741569
if sys.version_info >= (3, 14):
14751570
@overload
@@ -1776,7 +1871,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
17761871
quit: _sitebuiltins.Quitter
17771872

17781873
@disjoint_base
1779-
class reversed(Iterator[_T]):
1874+
class reversed(Generic[_T]):
17801875
@overload
17811876
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
17821877
@overload
@@ -1827,7 +1922,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
18271922
# without creating many false-positive errors (see #7578).
18281923
# Instead, we special-case the most common examples of this: bool and literal integers.
18291924
@overload
1830-
def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
1925+
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
18311926
@overload
18321927
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
18331928
@overload
@@ -1840,7 +1935,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
18401935
@overload
18411936
def vars(object: Any = ..., /) -> dict[str, Any]: ...
18421937
@disjoint_base
1843-
class zip(Iterator[_T_co]):
1938+
class zip(Generic[_T_co]):
18441939
if sys.version_info >= (3, 10):
18451940
@overload
18461941
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...

mypy/typeshed/stdlib/csv.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else:
2525
from _csv import _reader as Reader, _writer as Writer
2626

2727
from _typeshed import SupportsWrite
28-
from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence
28+
from collections.abc import Collection, Iterable, Mapping, Sequence
2929
from types import GenericAlias
3030
from typing import Any, Generic, Literal, TypeVar, overload
3131
from typing_extensions import Self
@@ -73,7 +73,7 @@ class excel(Dialect): ...
7373
class excel_tab(excel): ...
7474
class unix_dialect(Dialect): ...
7575

76-
class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]):
76+
class DictReader(Generic[_T]):
7777
fieldnames: Sequence[_T] | None
7878
restkey: _T | None
7979
restval: str | Any | None

mypy/typeshed/stdlib/fileinput.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22
from _typeshed import AnyStr_co, StrOrBytesPath
3-
from collections.abc import Callable, Iterable, Iterator
3+
from collections.abc import Callable, Iterable
44
from types import GenericAlias, TracebackType
5-
from typing import IO, Any, AnyStr, Literal, Protocol, overload, type_check_only
5+
from typing import IO, Any, AnyStr, Generic, Literal, Protocol, overload, type_check_only
66
from typing_extensions import Self, TypeAlias
77

88
__all__ = [
@@ -105,7 +105,7 @@ def fileno() -> int: ...
105105
def isfirstline() -> bool: ...
106106
def isstdin() -> bool: ...
107107

108-
class FileInput(Iterator[AnyStr]):
108+
class FileInput(Generic[AnyStr]):
109109
if sys.version_info >= (3, 10):
110110
# encoding and errors are added
111111
@overload

0 commit comments

Comments
 (0)