Skip to content

Commit 31b9085

Browse files
committed
Sync typeshed
Source commit: python/typeshed@633a4d7
1 parent 04ffee1 commit 31b9085

27 files changed

+648
-280
lines changed

mypy/typeshed/stdlib/VERSIONS

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ _msi: 3.0-3.12
5757
_multibytecodec: 3.0-
5858
_operator: 3.4-
5959
_osx_support: 3.0-
60+
_pickle: 3.0-
6061
_posixsubprocess: 3.2-
6162
_py_abc: 3.7-
6263
_pydecimal: 3.5-

mypy/typeshed/stdlib/_ctypes.pyi

+5-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
286286
def _type_(self) -> type[_CT]: ...
287287
@_type_.setter
288288
def _type_(self, value: type[_CT]) -> None: ...
289-
raw: bytes # Note: only available if _CT == c_char
289+
# Note: only available if _CT == c_char
290+
@property
291+
def raw(self) -> bytes: ...
292+
@raw.setter
293+
def raw(self, value: ReadableBuffer) -> None: ...
290294
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
291295
# TODO These methods cannot be annotated correctly at the moment.
292296
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
+19-127
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import sys
2-
from _thread import _excepthook, _ExceptHookArgs
1+
from _threading_local import local as local
32
from _typeshed import ProfileFunction, TraceFunction
4-
from collections.abc import Callable, Iterable, Mapping
5-
from types import TracebackType
6-
from typing import Any, TypeVar
7-
8-
_T = TypeVar("_T")
3+
from threading import (
4+
TIMEOUT_MAX as TIMEOUT_MAX,
5+
Barrier as Barrier,
6+
BoundedSemaphore as BoundedSemaphore,
7+
BrokenBarrierError as BrokenBarrierError,
8+
Condition as Condition,
9+
Event as Event,
10+
ExceptHookArgs as ExceptHookArgs,
11+
Lock as Lock,
12+
RLock as RLock,
13+
Semaphore as Semaphore,
14+
Thread as Thread,
15+
ThreadError as ThreadError,
16+
Timer as Timer,
17+
_DummyThread as _DummyThread,
18+
_RLock as _RLock,
19+
excepthook as excepthook,
20+
)
921

1022
__all__ = [
1123
"get_ident",
@@ -42,123 +54,3 @@ def main_thread() -> Thread: ...
4254
def settrace(func: TraceFunction) -> None: ...
4355
def setprofile(func: ProfileFunction | None) -> None: ...
4456
def stack_size(size: int | None = None) -> int: ...
45-
46-
TIMEOUT_MAX: float
47-
48-
class ThreadError(Exception): ...
49-
50-
class local:
51-
def __getattribute__(self, name: str) -> Any: ...
52-
def __setattr__(self, name: str, value: Any) -> None: ...
53-
def __delattr__(self, name: str) -> None: ...
54-
55-
class Thread:
56-
name: str
57-
daemon: bool
58-
@property
59-
def ident(self) -> int | None: ...
60-
def __init__(
61-
self,
62-
group: None = None,
63-
target: Callable[..., object] | None = None,
64-
name: str | None = None,
65-
args: Iterable[Any] = (),
66-
kwargs: Mapping[str, Any] | None = None,
67-
*,
68-
daemon: bool | None = None,
69-
) -> None: ...
70-
def start(self) -> None: ...
71-
def run(self) -> None: ...
72-
def join(self, timeout: float | None = None) -> None: ...
73-
def getName(self) -> str: ...
74-
def setName(self, name: str) -> None: ...
75-
@property
76-
def native_id(self) -> int | None: ... # only available on some platforms
77-
def is_alive(self) -> bool: ...
78-
if sys.version_info < (3, 9):
79-
def isAlive(self) -> bool: ...
80-
81-
def isDaemon(self) -> bool: ...
82-
def setDaemon(self, daemonic: bool) -> None: ...
83-
84-
class _DummyThread(Thread): ...
85-
86-
class Lock:
87-
def __enter__(self) -> bool: ...
88-
def __exit__(
89-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
90-
) -> bool | None: ...
91-
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
92-
def release(self) -> None: ...
93-
def locked(self) -> bool: ...
94-
95-
class _RLock:
96-
def __enter__(self) -> bool: ...
97-
def __exit__(
98-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
99-
) -> bool | None: ...
100-
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
101-
def release(self) -> None: ...
102-
103-
RLock = _RLock
104-
105-
class Condition:
106-
def __init__(self, lock: Lock | _RLock | None = None) -> None: ...
107-
def __enter__(self) -> bool: ...
108-
def __exit__(
109-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
110-
) -> bool | None: ...
111-
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
112-
def release(self) -> None: ...
113-
def wait(self, timeout: float | None = None) -> bool: ...
114-
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
115-
def notify(self, n: int = 1) -> None: ...
116-
def notify_all(self) -> None: ...
117-
def notifyAll(self) -> None: ...
118-
119-
class Semaphore:
120-
def __init__(self, value: int = 1) -> None: ...
121-
def __exit__(
122-
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
123-
) -> bool | None: ...
124-
def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
125-
def __enter__(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
126-
if sys.version_info >= (3, 9):
127-
def release(self, n: int = ...) -> None: ...
128-
else:
129-
def release(self) -> None: ...
130-
131-
class BoundedSemaphore(Semaphore): ...
132-
133-
class Event:
134-
def is_set(self) -> bool: ...
135-
def set(self) -> None: ...
136-
def clear(self) -> None: ...
137-
def wait(self, timeout: float | None = None) -> bool: ...
138-
139-
excepthook = _excepthook
140-
ExceptHookArgs = _ExceptHookArgs
141-
142-
class Timer(Thread):
143-
def __init__(
144-
self,
145-
interval: float,
146-
function: Callable[..., object],
147-
args: Iterable[Any] | None = None,
148-
kwargs: Mapping[str, Any] | None = None,
149-
) -> None: ...
150-
def cancel(self) -> None: ...
151-
152-
class Barrier:
153-
@property
154-
def parties(self) -> int: ...
155-
@property
156-
def n_waiting(self) -> int: ...
157-
@property
158-
def broken(self) -> bool: ...
159-
def __init__(self, parties: int, action: Callable[[], None] | None = None, timeout: float | None = None) -> None: ...
160-
def wait(self, timeout: float | None = None) -> int: ...
161-
def reset(self) -> None: ...
162-
def abort(self) -> None: ...
163-
164-
class BrokenBarrierError(RuntimeError): ...

mypy/typeshed/stdlib/_pickle.pyi

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import sys
2+
from _typeshed import ReadableBuffer, SupportsWrite
3+
from collections.abc import Callable, Iterable, Iterator, Mapping
4+
from pickle import PickleBuffer as PickleBuffer
5+
from typing import Any, Protocol, type_check_only
6+
from typing_extensions import TypeAlias
7+
8+
class _ReadableFileobj(Protocol):
9+
def read(self, n: int, /) -> bytes: ...
10+
def readline(self) -> bytes: ...
11+
12+
_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
13+
14+
_ReducedType: TypeAlias = (
15+
str
16+
| tuple[Callable[..., Any], tuple[Any, ...]]
17+
| tuple[Callable[..., Any], tuple[Any, ...], Any]
18+
| tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None]
19+
| tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None]
20+
)
21+
22+
def dump(
23+
obj: Any,
24+
file: SupportsWrite[bytes],
25+
protocol: int | None = None,
26+
*,
27+
fix_imports: bool = True,
28+
buffer_callback: _BufferCallback = None,
29+
) -> None: ...
30+
def dumps(
31+
obj: Any, protocol: int | None = None, *, fix_imports: bool = True, buffer_callback: _BufferCallback = None
32+
) -> bytes: ...
33+
def load(
34+
file: _ReadableFileobj,
35+
*,
36+
fix_imports: bool = True,
37+
encoding: str = "ASCII",
38+
errors: str = "strict",
39+
buffers: Iterable[Any] | None = (),
40+
) -> Any: ...
41+
def loads(
42+
data: ReadableBuffer,
43+
/,
44+
*,
45+
fix_imports: bool = True,
46+
encoding: str = "ASCII",
47+
errors: str = "strict",
48+
buffers: Iterable[Any] | None = (),
49+
) -> Any: ...
50+
51+
class PickleError(Exception): ...
52+
class PicklingError(PickleError): ...
53+
class UnpicklingError(PickleError): ...
54+
55+
@type_check_only
56+
class PicklerMemoProxy:
57+
def clear(self, /) -> None: ...
58+
def copy(self, /) -> dict[int, tuple[int, Any]]: ...
59+
60+
class Pickler:
61+
fast: bool
62+
dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
63+
reducer_override: Callable[[Any], Any]
64+
bin: bool # undocumented
65+
def __init__(
66+
self,
67+
file: SupportsWrite[bytes],
68+
protocol: int | None = None,
69+
*,
70+
fix_imports: bool = True,
71+
buffer_callback: _BufferCallback = None,
72+
) -> None: ...
73+
@property
74+
def memo(self) -> PicklerMemoProxy: ...
75+
@memo.setter
76+
def memo(self, value: PicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
77+
def dump(self, obj: Any, /) -> None: ...
78+
def clear_memo(self) -> None: ...
79+
if sys.version_info >= (3, 13):
80+
def persistent_id(self, obj: Any, /) -> Any: ...
81+
else:
82+
persistent_id: Callable[[Any], Any]
83+
84+
@type_check_only
85+
class UnpicklerMemoProxy:
86+
def clear(self, /) -> None: ...
87+
def copy(self, /) -> dict[int, tuple[int, Any]]: ...
88+
89+
class Unpickler:
90+
def __init__(
91+
self,
92+
file: _ReadableFileobj,
93+
*,
94+
fix_imports: bool = True,
95+
encoding: str = "ASCII",
96+
errors: str = "strict",
97+
buffers: Iterable[Any] | None = (),
98+
) -> None: ...
99+
@property
100+
def memo(self) -> UnpicklerMemoProxy: ...
101+
@memo.setter
102+
def memo(self, value: UnpicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
103+
def load(self) -> Any: ...
104+
def find_class(self, module_name: str, global_name: str, /) -> Any: ...
105+
if sys.version_info >= (3, 13):
106+
def persistent_load(self, pid: Any, /) -> Any: ...
107+
else:
108+
persistent_load: Callable[[Any], Any]

mypy/typeshed/stdlib/_socket.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ if sys.platform == "win32":
7878
SO_EXCLUSIVEADDRUSE: int
7979
if sys.platform != "win32":
8080
SO_REUSEPORT: int
81+
if sys.platform != "darwin" or sys.version_info >= (3, 13):
82+
SO_BINDTODEVICE: int
83+
8184
if sys.platform != "win32" and sys.platform != "darwin":
82-
SO_BINDTODEVICE: int
8385
SO_DOMAIN: int
8486
SO_MARK: int
8587
SO_PASSCRED: int

mypy/typeshed/stdlib/_tkinter.pyi

+26-11
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,31 @@ TK_VERSION: Final[str]
113113
class TkttType:
114114
def deletetimerhandler(self): ...
115115

116-
def create(
117-
screenName: str | None = None,
118-
baseName: str = "",
119-
className: str = "Tk",
120-
interactive: bool = False,
121-
wantobjects: bool = False,
122-
wantTk: bool = True,
123-
sync: bool = False,
124-
use: str | None = None,
125-
/,
126-
): ...
116+
if sys.version_info >= (3, 13):
117+
def create(
118+
screenName: str | None = None,
119+
baseName: str = "",
120+
className: str = "Tk",
121+
interactive: bool = False,
122+
wantobjects: int = 0,
123+
wantTk: bool = True,
124+
sync: bool = False,
125+
use: str | None = None,
126+
/,
127+
): ...
128+
129+
else:
130+
def create(
131+
screenName: str | None = None,
132+
baseName: str = "",
133+
className: str = "Tk",
134+
interactive: bool = False,
135+
wantobjects: bool = False,
136+
wantTk: bool = True,
137+
sync: bool = False,
138+
use: str | None = None,
139+
/,
140+
): ...
141+
127142
def getbusywaitinterval(): ...
128143
def setbusywaitinterval(new_val, /): ...

mypy/typeshed/stdlib/argparse.pyi

+21-15
Original file line numberDiff line numberDiff line change
@@ -182,30 +182,30 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
182182
def add_subparsers(
183183
self: _ArgumentParserT,
184184
*,
185-
title: str = ...,
186-
description: str | None = ...,
187-
prog: str = ...,
185+
title: str = "subcommands",
186+
description: str | None = None,
187+
prog: str | None = None,
188188
action: type[Action] = ...,
189189
option_string: str = ...,
190-
dest: str | None = ...,
191-
required: bool = ...,
192-
help: str | None = ...,
193-
metavar: str | None = ...,
190+
dest: str | None = None,
191+
required: bool = False,
192+
help: str | None = None,
193+
metavar: str | None = None,
194194
) -> _SubParsersAction[_ArgumentParserT]: ...
195195
@overload
196196
def add_subparsers(
197197
self,
198198
*,
199-
title: str = ...,
200-
description: str | None = ...,
201-
prog: str = ...,
199+
title: str = "subcommands",
200+
description: str | None = None,
201+
prog: str | None = None,
202202
parser_class: type[_ArgumentParserT],
203203
action: type[Action] = ...,
204204
option_string: str = ...,
205-
dest: str | None = ...,
206-
required: bool = ...,
207-
help: str | None = ...,
208-
metavar: str | None = ...,
205+
dest: str | None = None,
206+
required: bool = False,
207+
help: str | None = None,
208+
metavar: str | None = None,
209209
) -> _SubParsersAction[_ArgumentParserT]: ...
210210
def print_usage(self, file: IO[str] | None = None) -> None: ...
211211
def print_help(self, file: IO[str] | None = None) -> None: ...
@@ -237,7 +237,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
237237
# undocumented
238238
def _get_optional_actions(self) -> list[Action]: ...
239239
def _get_positional_actions(self) -> list[Action]: ...
240-
def _parse_known_args(self, arg_strings: list[str], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
240+
if sys.version_info >= (3, 12):
241+
def _parse_known_args(
242+
self, arg_strings: list[str], namespace: Namespace, intermixed: bool
243+
) -> tuple[Namespace, list[str]]: ...
244+
else:
245+
def _parse_known_args(self, arg_strings: list[str], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
246+
241247
def _read_args_from_files(self, arg_strings: list[str]) -> list[str]: ...
242248
def _match_argument(self, action: Action, arg_strings_pattern: str) -> int: ...
243249
def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: str) -> list[int]: ...

0 commit comments

Comments
 (0)