Skip to content

Commit 375cead

Browse files
Sync vendored typeshed stubs (#14350)
1 parent 9ec690b commit 375cead

30 files changed

+472
-335
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d262beb07502cda412db2179fb406d45d1a9486f
1+
5052fa2f18db4493892e0f2775030683c9d06531

crates/red_knot_vendored/vendor/typeshed/stdlib/VERSIONS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ _asyncio: 3.0-
2424
_bisect: 3.0-
2525
_blake2: 3.6-
2626
_bootlocale: 3.4-3.9
27+
_bz2: 3.3-
2728
_codecs: 3.0-
2829
_collections_abc: 3.3-
2930
_compat_pickle: 3.1-
3031
_compression: 3.5-
32+
_contextvars: 3.7-
3133
_csv: 3.0-
3234
_ctypes: 3.0-
3335
_curses: 3.0-
36+
_dbm: 3.0-
3437
_decimal: 3.3-
3538
_dummy_thread: 3.0-3.8
3639
_dummy_threading: 3.0-3.8
3740
_frozen_importlib: 3.0-
3841
_frozen_importlib_external: 3.5-
42+
_gdbm: 3.0-
3943
_heapq: 3.0-
4044
_imp: 3.0-
4145
_interpchannels: 3.13-
@@ -45,19 +49,22 @@ _io: 3.0-
4549
_json: 3.0-
4650
_locale: 3.0-
4751
_lsprof: 3.0-
52+
_lzma: 3.3-
4853
_markupbase: 3.0-
4954
_msi: 3.0-3.12
5055
_operator: 3.4-
5156
_osx_support: 3.0-
5257
_posixsubprocess: 3.2-
5358
_py_abc: 3.7-
5459
_pydecimal: 3.5-
60+
_queue: 3.7-
5561
_random: 3.0-
5662
_sitebuiltins: 3.4-
5763
_socket: 3.0- # present in 3.0 at runtime, but not in typeshed
5864
_sqlite3: 3.0-
5965
_ssl: 3.0-
6066
_stat: 3.4-
67+
_struct: 3.0-
6168
_thread: 3.0-
6269
_threading_local: 3.0-
6370
_tkinter: 3.0-
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from _typeshed import ReadableBuffer
2+
from typing import final
3+
4+
@final
5+
class BZ2Compressor:
6+
def __init__(self, compresslevel: int = 9) -> None: ...
7+
def compress(self, data: ReadableBuffer, /) -> bytes: ...
8+
def flush(self) -> bytes: ...
9+
10+
@final
11+
class BZ2Decompressor:
12+
def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
13+
@property
14+
def eof(self) -> bool: ...
15+
@property
16+
def needs_input(self) -> bool: ...
17+
@property
18+
def unused_data(self) -> bytes: ...
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sys
2+
from collections.abc import Callable, Iterator, Mapping
3+
from typing import Any, ClassVar, Generic, TypeVar, final, overload
4+
from typing_extensions import ParamSpec
5+
6+
if sys.version_info >= (3, 9):
7+
from types import GenericAlias
8+
9+
_T = TypeVar("_T")
10+
_D = TypeVar("_D")
11+
_P = ParamSpec("_P")
12+
13+
@final
14+
class ContextVar(Generic[_T]):
15+
@overload
16+
def __init__(self, name: str) -> None: ...
17+
@overload
18+
def __init__(self, name: str, *, default: _T) -> None: ...
19+
def __hash__(self) -> int: ...
20+
@property
21+
def name(self) -> str: ...
22+
@overload
23+
def get(self) -> _T: ...
24+
@overload
25+
def get(self, default: _T, /) -> _T: ...
26+
@overload
27+
def get(self, default: _D, /) -> _D | _T: ...
28+
def set(self, value: _T, /) -> Token[_T]: ...
29+
def reset(self, token: Token[_T], /) -> None: ...
30+
if sys.version_info >= (3, 9):
31+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
32+
33+
@final
34+
class Token(Generic[_T]):
35+
@property
36+
def var(self) -> ContextVar[_T]: ...
37+
@property
38+
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
39+
MISSING: ClassVar[object]
40+
if sys.version_info >= (3, 9):
41+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
42+
43+
def copy_context() -> Context: ...
44+
45+
# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
46+
# a different value.
47+
@final
48+
class Context(Mapping[ContextVar[Any], Any]):
49+
def __init__(self) -> None: ...
50+
@overload
51+
def get(self, key: ContextVar[_T], default: None = None, /) -> _T | None: ...
52+
@overload
53+
def get(self, key: ContextVar[_T], default: _T, /) -> _T: ...
54+
@overload
55+
def get(self, key: ContextVar[_T], default: _D, /) -> _T | _D: ...
56+
def run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
57+
def copy(self) -> Context: ...
58+
def __getitem__(self, key: ContextVar[_T], /) -> _T: ...
59+
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
60+
def __len__(self) -> int: ...
61+
def __eq__(self, value: object, /) -> bool: ...
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
3+
from types import TracebackType
4+
from typing import TypeVar, overload
5+
from typing_extensions import Self, TypeAlias
6+
7+
if sys.platform != "win32":
8+
_T = TypeVar("_T")
9+
_KeyType: TypeAlias = str | ReadOnlyBuffer
10+
_ValueType: TypeAlias = str | ReadOnlyBuffer
11+
12+
class error(OSError): ...
13+
library: str
14+
15+
# Actual typename dbm, not exposed by the implementation
16+
class _dbm:
17+
def close(self) -> None: ...
18+
if sys.version_info >= (3, 13):
19+
def clear(self) -> None: ...
20+
21+
def __getitem__(self, item: _KeyType) -> bytes: ...
22+
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
23+
def __delitem__(self, key: _KeyType) -> None: ...
24+
def __len__(self) -> int: ...
25+
def __del__(self) -> None: ...
26+
def __enter__(self) -> Self: ...
27+
def __exit__(
28+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
29+
) -> None: ...
30+
@overload
31+
def get(self, k: _KeyType) -> bytes | None: ...
32+
@overload
33+
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
34+
def keys(self) -> list[bytes]: ...
35+
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
36+
# Don't exist at runtime
37+
__new__: None # type: ignore[assignment]
38+
__init__: None # type: ignore[assignment]
39+
40+
if sys.version_info >= (3, 11):
41+
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...
42+
else:
43+
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _dbm: ...

crates/red_knot_vendored/vendor/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: ...
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
from _typeshed import ReadOnlyBuffer, StrOrBytesPath
3+
from types import TracebackType
4+
from typing import TypeVar, overload
5+
from typing_extensions import Self, TypeAlias
6+
7+
if sys.platform != "win32":
8+
_T = TypeVar("_T")
9+
_KeyType: TypeAlias = str | ReadOnlyBuffer
10+
_ValueType: TypeAlias = str | ReadOnlyBuffer
11+
12+
open_flags: str
13+
14+
class error(OSError): ...
15+
# Actual typename gdbm, not exposed by the implementation
16+
class _gdbm:
17+
def firstkey(self) -> bytes | None: ...
18+
def nextkey(self, key: _KeyType) -> bytes | None: ...
19+
def reorganize(self) -> None: ...
20+
def sync(self) -> None: ...
21+
def close(self) -> None: ...
22+
if sys.version_info >= (3, 13):
23+
def clear(self) -> None: ...
24+
25+
def __getitem__(self, item: _KeyType) -> bytes: ...
26+
def __setitem__(self, key: _KeyType, value: _ValueType) -> None: ...
27+
def __delitem__(self, key: _KeyType) -> None: ...
28+
def __contains__(self, key: _KeyType) -> bool: ...
29+
def __len__(self) -> int: ...
30+
def __enter__(self) -> Self: ...
31+
def __exit__(
32+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
33+
) -> None: ...
34+
@overload
35+
def get(self, k: _KeyType) -> bytes | None: ...
36+
@overload
37+
def get(self, k: _KeyType, default: _T) -> bytes | _T: ...
38+
def keys(self) -> list[bytes]: ...
39+
def setdefault(self, k: _KeyType, default: _ValueType = ...) -> bytes: ...
40+
# Don't exist at runtime
41+
__new__: None # type: ignore[assignment]
42+
__init__: None # type: ignore[assignment]
43+
44+
if sys.version_info >= (3, 11):
45+
def open(filename: StrOrBytesPath, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...
46+
else:
47+
def open(filename: str, flags: str = "r", mode: int = 0o666, /) -> _gdbm: ...

crates/red_knot_vendored/vendor/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: ...

0 commit comments

Comments
 (0)