Skip to content

Commit eedee20

Browse files
Sync typeshed (#18114)
Source commit: python/typeshed@3d853d5
1 parent 78fb78b commit eedee20

File tree

9 files changed

+66
-37
lines changed

9 files changed

+66
-37
lines changed

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

Lines changed: 2 additions & 2 deletions
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

Lines changed: 23 additions & 11 deletions
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

Lines changed: 2 additions & 1 deletion
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/distutils/ccompiler.pyi

Lines changed: 2 additions & 2 deletions
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

Lines changed: 6 additions & 2 deletions
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

mypy/typeshed/stdlib/ipaddress.pyi

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ class _BaseNetwork(_IPAddressBase, Generic[_A]):
128128
@property
129129
def hostmask(self) -> _A: ...
130130

131-
class _BaseInterface(_BaseAddress, Generic[_A, _N]):
132-
hostmask: _A
133-
netmask: _A
134-
network: _N
135-
@property
136-
def ip(self) -> _A: ...
137-
@property
138-
def with_hostmask(self) -> str: ...
139-
@property
140-
def with_netmask(self) -> str: ...
141-
@property
142-
def with_prefixlen(self) -> str: ...
143-
144131
class _BaseV4:
145132
@property
146133
def version(self) -> Literal[4]: ...
@@ -154,9 +141,21 @@ class IPv4Address(_BaseV4, _BaseAddress):
154141

155142
class IPv4Network(_BaseV4, _BaseNetwork[IPv4Address]): ...
156143

157-
class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]):
144+
class IPv4Interface(IPv4Address):
145+
netmask: IPv4Address
146+
network: IPv4Network
158147
def __eq__(self, other: object) -> bool: ...
159148
def __hash__(self) -> int: ...
149+
@property
150+
def hostmask(self) -> IPv4Address: ...
151+
@property
152+
def ip(self) -> IPv4Address: ...
153+
@property
154+
def with_hostmask(self) -> str: ...
155+
@property
156+
def with_netmask(self) -> str: ...
157+
@property
158+
def with_prefixlen(self) -> str: ...
160159

161160
class _BaseV6:
162161
@property
@@ -184,9 +183,21 @@ class IPv6Network(_BaseV6, _BaseNetwork[IPv6Address]):
184183
@property
185184
def is_site_local(self) -> bool: ...
186185

187-
class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]):
186+
class IPv6Interface(IPv6Address):
187+
netmask: IPv6Address
188+
network: IPv6Network
188189
def __eq__(self, other: object) -> bool: ...
189190
def __hash__(self) -> int: ...
191+
@property
192+
def hostmask(self) -> IPv6Address: ...
193+
@property
194+
def ip(self) -> IPv6Address: ...
195+
@property
196+
def with_hostmask(self) -> str: ...
197+
@property
198+
def with_netmask(self) -> str: ...
199+
@property
200+
def with_prefixlen(self) -> str: ...
190201

191202
def v4_int_to_packed(address: int) -> bytes: ...
192203
def v6_int_to_packed(address: int) -> bytes: ...

mypy/typeshed/stdlib/multiprocessing/managers.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from typing_extensions import Self, TypeAlias
1010
from .connection import Connection
1111
from .context import BaseContext
1212
from .shared_memory import _SLT, ShareableList as _ShareableList, SharedMemory as _SharedMemory
13+
from .util import Finalize as _Finalize
1314

1415
__all__ = ["BaseManager", "SyncManager", "BaseProxy", "Token", "SharedMemoryManager"]
1516

@@ -156,7 +157,7 @@ class BaseManager:
156157
def get_server(self) -> Server: ...
157158
def connect(self) -> None: ...
158159
def start(self, initializer: Callable[..., object] | None = None, initargs: Iterable[Any] = ()) -> None: ...
159-
def shutdown(self) -> None: ... # only available after start() was called
160+
shutdown: _Finalize # only available after start() was called
160161
def join(self, timeout: float | None = None) -> None: ... # undocumented
161162
@property
162163
def address(self) -> Any: ...

mypy/typeshed/stdlib/multiprocessing/spawn.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_command_line(**kwds: Any) -> list[str]: ...
2323
def spawn_main(pipe_handle: int, parent_pid: int | None = None, tracker_fd: int | None = None) -> None: ...
2424

2525
# undocumented
26-
def _main(fd: int) -> Any: ...
26+
def _main(fd: int, parent_sentinel: int) -> int: ...
2727
def get_preparation_data(name: str) -> dict[str, Any]: ...
2828

2929
old_main_modules: list[ModuleType]

mypy/typeshed/stdlib/tarfile.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bz2
22
import io
33
import sys
4-
from _typeshed import StrOrBytesPath, StrPath
4+
from _typeshed import StrOrBytesPath, StrPath, SupportsRead
55
from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list"
66
from collections.abc import Callable, Iterable, Iterator, Mapping
77
from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj
@@ -481,7 +481,7 @@ class TarFile:
481481
*,
482482
filter: Callable[[TarInfo], TarInfo | None] | None = None,
483483
) -> None: ...
484-
def addfile(self, tarinfo: TarInfo, fileobj: IO[bytes] | None = None) -> None: ...
484+
def addfile(self, tarinfo: TarInfo, fileobj: SupportsRead[bytes] | None = None) -> None: ...
485485
def gettarinfo(
486486
self, name: StrOrBytesPath | None = None, arcname: str | None = None, fileobj: IO[bytes] | None = None
487487
) -> TarInfo: ...

0 commit comments

Comments
 (0)