Skip to content

Commit 11fc126

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@3d853d5
1 parent 78fb78b commit 11fc126

File tree

11 files changed

+171
-40
lines changed

11 files changed

+171
-40
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

+5-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ class Array(_CData, Generic[_CT]):
171171
def _type_(self) -> type[_CT]: ...
172172
@_type_.setter
173173
def _type_(self, value: type[_CT]) -> None: ...
174-
raw: bytes # Note: only available if _CT == c_char
174+
# Note: only available if _CT == c_char
175+
@property
176+
def raw(self) -> bytes: ...
177+
@raw.setter
178+
def raw(self, value: ReadableBuffer) -> None: ...
175179
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
176180
# TODO These methods cannot be annotated correctly at the moment.
177181
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class FileLoader:
107107
def get_filename(self, name: str | None = None) -> str: ...
108108
def load_module(self, name: str | None = None) -> types.ModuleType: ...
109109
if sys.version_info >= (3, 10):
110-
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.FileReader: ...
110+
def get_resource_reader(self, name: str | None = None) -> importlib.readers.FileReader: ...
111111
else:
112-
def get_resource_reader(self, module: types.ModuleType) -> Self | None: ...
112+
def get_resource_reader(self, name: str | None = None) -> Self | None: ...
113113
def open_resource(self, resource: str) -> _io.FileIO: ...
114114
def resource_path(self, resource: str) -> str: ...
115115
def is_resource(self, name: str) -> bool: ...

mypy/typeshed/stdlib/_io.pyi

+23-11
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class _IOBase:
3333
def readable(self) -> bool: ...
3434
read: Callable[..., Any]
3535
def readlines(self, hint: int = -1, /) -> list[bytes]: ...
36-
def seek(self, offset: int, whence: int = ..., /) -> int: ...
36+
def seek(self, offset: int, whence: int = 0, /) -> int: ...
3737
def seekable(self) -> bool: ...
3838
def tell(self) -> int: ...
39-
def truncate(self, size: int | None = ..., /) -> int: ...
39+
def truncate(self, size: int | None = None, /) -> int: ...
4040
def writable(self) -> bool: ...
4141
write: Callable[..., Any]
4242
def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ...
@@ -59,8 +59,8 @@ class _BufferedIOBase(_IOBase):
5959
def readinto(self, buffer: WriteableBuffer, /) -> int: ...
6060
def write(self, buffer: ReadableBuffer, /) -> int: ...
6161
def readinto1(self, buffer: WriteableBuffer, /) -> int: ...
62-
def read(self, size: int | None = ..., /) -> bytes: ...
63-
def read1(self, size: int = ..., /) -> bytes: ...
62+
def read(self, size: int | None = -1, /) -> bytes: ...
63+
def read1(self, size: int = -1, /) -> bytes: ...
6464

6565
class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
6666
mode: str
@@ -69,30 +69,38 @@ class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompat
6969
# "name" is a str. In the future, making FileIO generic might help.
7070
name: Any
7171
def __init__(
72-
self, file: FileDescriptorOrPath, mode: str = ..., closefd: bool = ..., opener: _Opener | None = ...
72+
self, file: FileDescriptorOrPath, mode: str = "r", closefd: bool = True, opener: _Opener | None = None
7373
) -> None: ...
7474
@property
7575
def closefd(self) -> bool: ...
76+
def seek(self, pos: int, whence: int = 0, /) -> int: ...
77+
def read(self, size: int | None = -1, /) -> bytes | MaybeNone: ...
7678

7779
class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
78-
def __init__(self, initial_bytes: ReadableBuffer = ...) -> None: ...
80+
def __init__(self, initial_bytes: ReadableBuffer = b"") -> None: ...
7981
# BytesIO does not contain a "name" field. This workaround is necessary
8082
# to allow BytesIO sub-classes to add this field, as it is defined
8183
# as a read-only property on IO[].
8284
name: Any
8385
def getvalue(self) -> bytes: ...
8486
def getbuffer(self) -> memoryview: ...
8587
def read1(self, size: int | None = -1, /) -> bytes: ...
88+
def readlines(self, size: int | None = None, /) -> list[bytes]: ...
89+
def seek(self, pos: int, whence: int = 0, /) -> int: ...
8690

8791
class BufferedReader(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
8892
raw: RawIOBase
8993
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
9094
def peek(self, size: int = 0, /) -> bytes: ...
95+
def seek(self, target: int, whence: int = 0, /) -> int: ...
96+
def truncate(self, pos: int | None = None, /) -> int: ...
9197

9298
class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes
9399
raw: RawIOBase
94100
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
95101
def write(self, buffer: ReadableBuffer, /) -> int: ...
102+
def seek(self, target: int, whence: int = 0, /) -> int: ...
103+
def truncate(self, pos: int | None = None, /) -> int: ...
96104

97105
class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes
98106
mode: str
@@ -101,10 +109,11 @@ class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore
101109
def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ...
102110
def seek(self, target: int, whence: int = 0, /) -> int: ... # stubtest needs this
103111
def peek(self, size: int = 0, /) -> bytes: ...
112+
def truncate(self, pos: int | None = None, /) -> int: ...
104113

105114
class BufferedRWPair(BufferedIOBase, _BufferedIOBase):
106115
def __init__(self, reader: RawIOBase, writer: RawIOBase, buffer_size: int = 8192) -> None: ...
107-
def peek(self, size: int = ..., /) -> bytes: ...
116+
def peek(self, size: int = 0, /) -> bytes: ...
108117

109118
class _TextIOBase(_IOBase):
110119
encoding: str
@@ -115,9 +124,9 @@ class _TextIOBase(_IOBase):
115124
def detach(self) -> BinaryIO: ...
116125
def write(self, s: str, /) -> int: ...
117126
def writelines(self, lines: Iterable[str], /) -> None: ... # type: ignore[override]
118-
def readline(self, size: int = ..., /) -> str: ... # type: ignore[override]
127+
def readline(self, size: int = -1, /) -> str: ... # type: ignore[override]
119128
def readlines(self, hint: int = -1, /) -> list[str]: ... # type: ignore[override]
120-
def read(self, size: int | None = ..., /) -> str: ...
129+
def read(self, size: int | None = -1, /) -> str: ...
121130

122131
@type_check_only
123132
class _WrappedBuffer(Protocol):
@@ -177,19 +186,22 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t
177186
# TextIOWrapper's version of seek only supports a limited subset of
178187
# operations.
179188
def seek(self, cookie: int, whence: int = 0, /) -> int: ...
189+
def truncate(self, pos: int | None = None, /) -> int: ...
180190

181191
class StringIO(TextIOBase, _TextIOBase, TextIO): # type: ignore[misc] # incompatible definitions of write in the base classes
182-
def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ...
192+
def __init__(self, initial_value: str | None = "", newline: str | None = "\n") -> None: ...
183193
# StringIO does not contain a "name" field. This workaround is necessary
184194
# to allow StringIO sub-classes to add this field, as it is defined
185195
# as a read-only property on IO[].
186196
name: Any
187197
def getvalue(self) -> str: ...
188198
@property
189199
def line_buffering(self) -> bool: ...
200+
def seek(self, pos: int, whence: int = 0, /) -> int: ...
201+
def truncate(self, pos: int | None = None, /) -> int: ...
190202

191203
class IncrementalNewlineDecoder:
192-
def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ...
204+
def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = "strict") -> None: ...
193205
def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ...
194206
@property
195207
def newlines(self) -> str | tuple[str, ...] | None: ...

mypy/typeshed/stdlib/_threading_local.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Any
2-
from typing_extensions import TypeAlias
2+
from typing_extensions import Self, TypeAlias
33
from weakref import ReferenceType
44

55
__all__ = ["local"]
@@ -12,6 +12,7 @@ class _localimpl:
1212
def create_dict(self) -> _LocalDict: ...
1313

1414
class local:
15+
def __new__(cls, /, *args: Any, **kw: Any) -> Self: ...
1516
def __getattribute__(self, name: str) -> Any: ...
1617
def __setattr__(self, name: str, value: Any) -> None: ...
1718
def __delattr__(self, name: str) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

+100-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ from typing import ( # noqa: Y022
6464
from typing_extensions import ( # noqa: Y023
6565
Concatenate,
6666
Literal,
67+
LiteralString,
6768
ParamSpec,
6869
Self,
6970
TypeAlias,
@@ -441,16 +442,31 @@ class str(Sequence[str]):
441442
def __new__(cls, object: object = ...) -> Self: ...
442443
@overload
443444
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
445+
@overload
446+
def capitalize(self: LiteralString) -> LiteralString: ...
447+
@overload
444448
def capitalize(self) -> str: ... # type: ignore[misc]
449+
@overload
450+
def casefold(self: LiteralString) -> LiteralString: ...
451+
@overload
445452
def casefold(self) -> str: ... # type: ignore[misc]
453+
@overload
454+
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
455+
@overload
446456
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
447457
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
448458
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
449459
def endswith(
450460
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
451461
) -> bool: ...
462+
@overload
463+
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
464+
@overload
452465
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
453466
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
467+
@overload
468+
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
469+
@overload
454470
def format(self, *args: object, **kwargs: object) -> str: ...
455471
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
456472
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -466,35 +482,99 @@ class str(Sequence[str]):
466482
def isspace(self) -> bool: ...
467483
def istitle(self) -> bool: ...
468484
def isupper(self) -> bool: ...
485+
@overload
486+
def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
487+
@overload
469488
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
489+
@overload
490+
def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
491+
@overload
470492
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
493+
@overload
494+
def lower(self: LiteralString) -> LiteralString: ...
495+
@overload
471496
def lower(self) -> str: ... # type: ignore[misc]
497+
@overload
498+
def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
499+
@overload
472500
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
501+
@overload
502+
def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
503+
@overload
473504
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
474505
if sys.version_info >= (3, 13):
506+
@overload
507+
def replace(
508+
self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
509+
) -> LiteralString: ...
510+
@overload
475511
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
476512
else:
513+
@overload
514+
def replace(
515+
self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
516+
) -> LiteralString: ...
517+
@overload
477518
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
478519
if sys.version_info >= (3, 9):
520+
@overload
521+
def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
522+
@overload
479523
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
524+
@overload
525+
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
526+
@overload
480527
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
481528

482529
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
483530
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
531+
@overload
532+
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
533+
@overload
484534
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
535+
@overload
536+
def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
537+
@overload
485538
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
539+
@overload
540+
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
541+
@overload
486542
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
543+
@overload
544+
def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
545+
@overload
487546
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
547+
@overload
548+
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
549+
@overload
488550
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
551+
@overload
552+
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
553+
@overload
489554
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
490555
def startswith(
491556
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
492557
) -> bool: ...
558+
@overload
559+
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
560+
@overload
493561
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
562+
@overload
563+
def swapcase(self: LiteralString) -> LiteralString: ...
564+
@overload
494565
def swapcase(self) -> str: ... # type: ignore[misc]
566+
@overload
567+
def title(self: LiteralString) -> LiteralString: ...
568+
@overload
495569
def title(self) -> str: ... # type: ignore[misc]
496570
def translate(self, table: _TranslateTable, /) -> str: ...
571+
@overload
572+
def upper(self: LiteralString) -> LiteralString: ...
573+
@overload
497574
def upper(self) -> str: ... # type: ignore[misc]
575+
@overload
576+
def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
577+
@overload
498578
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
499579
@staticmethod
500580
@overload
@@ -505,21 +585,39 @@ class str(Sequence[str]):
505585
@staticmethod
506586
@overload
507587
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
588+
@overload
589+
def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
590+
@overload
508591
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
509592
# Incompatible with Sequence.__contains__
510593
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
511594
def __eq__(self, value: object, /) -> bool: ...
512595
def __ge__(self, value: str, /) -> bool: ...
513-
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
596+
@overload
597+
def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
598+
@overload
599+
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
514600
def __gt__(self, value: str, /) -> bool: ...
515601
def __hash__(self) -> int: ...
602+
@overload
603+
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
604+
@overload
516605
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
517606
def __le__(self, value: str, /) -> bool: ...
518607
def __len__(self) -> int: ...
519608
def __lt__(self, value: str, /) -> bool: ...
609+
@overload
610+
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
611+
@overload
520612
def __mod__(self, value: Any, /) -> str: ...
613+
@overload
614+
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
615+
@overload
521616
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
522617
def __ne__(self, value: object, /) -> bool: ...
618+
@overload
619+
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
620+
@overload
523621
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
524622
def __getnewargs__(self) -> tuple[str]: ...
525623

@@ -1675,7 +1773,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
16751773
# without creating many false-positive errors (see #7578).
16761774
# Instead, we special-case the most common examples of this: bool and literal integers.
16771775
@overload
1678-
def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
1776+
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
16791777
@overload
16801778
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
16811779
@overload

mypy/typeshed/stdlib/distutils/ccompiler.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import BytesPath, StrPath, Unused
2-
from collections.abc import Callable, Iterable
2+
from collections.abc import Callable, Iterable, Sequence
33
from distutils.file_util import _BytesPathT, _StrPathT
44
from typing import Literal, overload
55
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
@@ -63,7 +63,7 @@ class CCompiler:
6363
def set_executables(self, **args: str) -> None: ...
6464
def compile(
6565
self,
66-
sources: list[str],
66+
sources: Sequence[StrPath],
6767
output_dir: str | None = None,
6868
macros: list[_Macro] | None = None,
6969
include_dirs: list[str] | None = None,

mypy/typeshed/stdlib/getopt.pyi

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from collections.abc import Iterable
2+
13
__all__ = ["GetoptError", "error", "getopt", "gnu_getopt"]
24

3-
def getopt(args: list[str], shortopts: str, longopts: list[str] = []) -> tuple[list[tuple[str, str]], list[str]]: ...
4-
def gnu_getopt(args: list[str], shortopts: str, longopts: list[str] = []) -> tuple[list[tuple[str, str]], list[str]]: ...
5+
def getopt(args: list[str], shortopts: str, longopts: Iterable[str] | str = []) -> tuple[list[tuple[str, str]], list[str]]: ...
6+
def gnu_getopt(
7+
args: list[str], shortopts: str, longopts: Iterable[str] | str = []
8+
) -> tuple[list[tuple[str, str]], list[str]]: ...
59

610
class GetoptError(Exception):
711
msg: str

0 commit comments

Comments
 (0)