Skip to content

Commit bc44f2c

Browse files
author
mypybot
committed
Sync typeshed
Source commit: python/typeshed@5052fa2
1 parent fa01a07 commit bc44f2c

22 files changed

+510
-300
lines changed

mypy/typeshed/stdlib/VERSIONS

+7
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-

mypy/typeshed/stdlib/_bz2.pyi

+18
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: ...

mypy/typeshed/stdlib/_contextvars.pyi

+61
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: ...

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/_dbm.pyi

+43
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: ...

mypy/typeshed/stdlib/_gdbm.pyi

+47
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: ...

mypy/typeshed/stdlib/_lzma.pyi

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from _typeshed import ReadableBuffer
2+
from collections.abc import Mapping, Sequence
3+
from typing import Any, Final, final
4+
from typing_extensions import TypeAlias
5+
6+
_FilterChain: TypeAlias = Sequence[Mapping[str, Any]]
7+
8+
FORMAT_AUTO: Final = 0
9+
FORMAT_XZ: Final = 1
10+
FORMAT_ALONE: Final = 2
11+
FORMAT_RAW: Final = 3
12+
CHECK_NONE: Final = 0
13+
CHECK_CRC32: Final = 1
14+
CHECK_CRC64: Final = 4
15+
CHECK_SHA256: Final = 10
16+
CHECK_ID_MAX: Final = 15
17+
CHECK_UNKNOWN: Final = 16
18+
FILTER_LZMA1: int # v big number
19+
FILTER_LZMA2: Final = 33
20+
FILTER_DELTA: Final = 3
21+
FILTER_X86: Final = 4
22+
FILTER_IA64: Final = 6
23+
FILTER_ARM: Final = 7
24+
FILTER_ARMTHUMB: Final = 8
25+
FILTER_SPARC: Final = 9
26+
FILTER_POWERPC: Final = 5
27+
MF_HC3: Final = 3
28+
MF_HC4: Final = 4
29+
MF_BT2: Final = 18
30+
MF_BT3: Final = 19
31+
MF_BT4: Final = 20
32+
MODE_FAST: Final = 1
33+
MODE_NORMAL: Final = 2
34+
PRESET_DEFAULT: Final = 6
35+
PRESET_EXTREME: int # v big number
36+
37+
@final
38+
class LZMADecompressor:
39+
def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ...
40+
def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
41+
@property
42+
def check(self) -> int: ...
43+
@property
44+
def eof(self) -> bool: ...
45+
@property
46+
def unused_data(self) -> bytes: ...
47+
@property
48+
def needs_input(self) -> bool: ...
49+
50+
@final
51+
class LZMACompressor:
52+
def __init__(
53+
self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ...
54+
) -> None: ...
55+
def compress(self, data: ReadableBuffer, /) -> bytes: ...
56+
def flush(self) -> bytes: ...
57+
58+
class LZMAError(Exception): ...
59+
60+
def is_check_supported(check_id: int, /) -> bool: ...

mypy/typeshed/stdlib/_queue.pyi

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
from typing import Any, Generic, TypeVar
3+
4+
if sys.version_info >= (3, 9):
5+
from types import GenericAlias
6+
7+
_T = TypeVar("_T")
8+
9+
class Empty(Exception): ...
10+
11+
class SimpleQueue(Generic[_T]):
12+
def __init__(self) -> None: ...
13+
def empty(self) -> bool: ...
14+
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
15+
def get_nowait(self) -> _T: ...
16+
def put(self, item: _T, block: bool = True, timeout: float | None = None) -> None: ...
17+
def put_nowait(self, item: _T) -> None: ...
18+
def qsize(self) -> int: ...
19+
if sys.version_info >= (3, 9):
20+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

mypy/typeshed/stdlib/_struct.pyi

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from _typeshed import ReadableBuffer, WriteableBuffer
2+
from collections.abc import Iterator
3+
from typing import Any
4+
5+
def pack(fmt: str | bytes, /, *v: Any) -> bytes: ...
6+
def pack_into(fmt: str | bytes, buffer: WriteableBuffer, offset: int, /, *v: Any) -> None: ...
7+
def unpack(format: str | bytes, buffer: ReadableBuffer, /) -> tuple[Any, ...]: ...
8+
def unpack_from(format: str | bytes, /, buffer: ReadableBuffer, offset: int = 0) -> tuple[Any, ...]: ...
9+
def iter_unpack(format: str | bytes, buffer: ReadableBuffer, /) -> Iterator[tuple[Any, ...]]: ...
10+
def calcsize(format: str | bytes, /) -> int: ...
11+
12+
class Struct:
13+
@property
14+
def format(self) -> str: ...
15+
@property
16+
def size(self) -> int: ...
17+
def __init__(self, format: str | bytes) -> None: ...
18+
def pack(self, *v: Any) -> bytes: ...
19+
def pack_into(self, buffer: WriteableBuffer, offset: int, *v: Any) -> None: ...
20+
def unpack(self, buffer: ReadableBuffer, /) -> tuple[Any, ...]: ...
21+
def unpack_from(self, buffer: ReadableBuffer, offset: int = 0) -> tuple[Any, ...]: ...
22+
def iter_unpack(self, buffer: ReadableBuffer, /) -> Iterator[tuple[Any, ...]]: ...

0 commit comments

Comments
 (0)