Skip to content

Commit 59a6c5e

Browse files
AlexWaygoodJelleZijlstra
authored andcommitted
Sync typeshed
Source commit: python/typeshed@c38fc45
1 parent 66b96ed commit 59a6c5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+899
-150
lines changed

mypy/typeshed/stdlib/VERSIONS

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ dbm: 2.7-
112112
decimal: 2.7-
113113
difflib: 2.7-
114114
dis: 2.7-
115-
distutils: 2.7-
115+
distutils: 2.7-3.11
116116
distutils.command.bdist_msi: 2.7-3.10
117117
distutils.command.bdist_wininst: 2.7-3.9
118118
doctest: 2.7-
@@ -147,7 +147,7 @@ html: 3.0-
147147
http: 3.0-
148148
imaplib: 2.7-
149149
imghdr: 2.7-
150-
imp: 2.7-
150+
imp: 2.7-3.11
151151
importlib: 2.7-
152152
importlib.metadata: 3.8-
153153
importlib.metadata._meta: 3.10-

mypy/typeshed/stdlib/_ast.pyi

+43-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import sys
2+
import typing_extensions
23
from typing import Any, ClassVar
3-
from typing_extensions import Literal, TypeAlias
4+
from typing_extensions import Literal
45

56
PyCF_ONLY_AST: Literal[1024]
67
if sys.version_info >= (3, 8):
78
PyCF_TYPE_COMMENTS: Literal[4096]
89
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
910

10-
_Identifier: TypeAlias = str
11+
_Identifier: typing_extensions.TypeAlias = str
1112

1213
class AST:
1314
if sys.version_info >= (3, 10):
@@ -59,31 +60,43 @@ class Expression(mod):
5960
class stmt(AST): ...
6061

6162
class FunctionDef(stmt):
62-
if sys.version_info >= (3, 10):
63+
if sys.version_info >= (3, 12):
64+
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
65+
elif sys.version_info >= (3, 10):
6366
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
6467
name: _Identifier
6568
args: arguments
6669
body: list[stmt]
6770
decorator_list: list[expr]
6871
returns: expr | None
72+
if sys.version_info >= (3, 12):
73+
type_params: list[type_param]
6974

7075
class AsyncFunctionDef(stmt):
71-
if sys.version_info >= (3, 10):
76+
if sys.version_info >= (3, 12):
77+
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
78+
elif sys.version_info >= (3, 10):
7279
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
7380
name: _Identifier
7481
args: arguments
7582
body: list[stmt]
7683
decorator_list: list[expr]
7784
returns: expr | None
85+
if sys.version_info >= (3, 12):
86+
type_params: list[type_param]
7887

7988
class ClassDef(stmt):
80-
if sys.version_info >= (3, 10):
89+
if sys.version_info >= (3, 12):
90+
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list", "type_params")
91+
elif sys.version_info >= (3, 10):
8192
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list")
8293
name: _Identifier
8394
bases: list[expr]
8495
keywords: list[keyword]
8596
body: list[stmt]
8697
decorator_list: list[expr]
98+
if sys.version_info >= (3, 12):
99+
type_params: list[type_param]
87100

88101
class Return(stmt):
89102
if sys.version_info >= (3, 10):
@@ -366,10 +379,10 @@ class Attribute(expr):
366379
ctx: expr_context
367380

368381
if sys.version_info >= (3, 9):
369-
_Slice: TypeAlias = expr
382+
_Slice: typing_extensions.TypeAlias = expr
370383
else:
371384
class slice(AST): ...
372-
_Slice: TypeAlias = slice
385+
_Slice: typing_extensions.TypeAlias = slice
373386

374387
class Slice(_Slice):
375388
if sys.version_info >= (3, 10):
@@ -526,7 +539,7 @@ if sys.version_info >= (3, 10):
526539

527540
class pattern(AST): ...
528541
# Without the alias, Pyright complains variables named pattern are recursively defined
529-
_Pattern: TypeAlias = pattern
542+
_Pattern: typing_extensions.TypeAlias = pattern
530543

531544
class match_case(AST):
532545
__match_args__ = ("pattern", "guard", "body")
@@ -571,3 +584,25 @@ if sys.version_info >= (3, 10):
571584
class MatchOr(pattern):
572585
__match_args__ = ("patterns",)
573586
patterns: list[pattern]
587+
588+
if sys.version_info >= (3, 12):
589+
class type_param(AST): ...
590+
591+
class TypeVar(type_param):
592+
__match_args__ = ("name", "bound")
593+
name: _Identifier
594+
bound: expr | None
595+
596+
class ParamSpec(type_param):
597+
__match_args__ = ("name",)
598+
name: _Identifier
599+
600+
class TypeVarTuple(type_param):
601+
__match_args__ = ("name",)
602+
name: _Identifier
603+
604+
class TypeAlias(stmt):
605+
__match_args__ = ("name", "typeparams", "value")
606+
name: Name
607+
type_params: list[type_param]
608+
value: expr

mypy/typeshed/stdlib/_csv.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from _typeshed import SupportsWrite
23
from collections.abc import Iterable, Iterator
34
from typing import Any
@@ -9,6 +10,9 @@ QUOTE_ALL: Literal[1]
910
QUOTE_MINIMAL: Literal[0]
1011
QUOTE_NONE: Literal[3]
1112
QUOTE_NONNUMERIC: Literal[2]
13+
if sys.version_info >= (3, 12):
14+
QUOTE_STRINGS: Literal[4]
15+
QUOTE_NOTNULL: Literal[5]
1216

1317
# Ideally this would be `QUOTE_ALL | QUOTE_MINIMAL | QUOTE_NONE | QUOTE_NONNUMERIC`
1418
# However, using literals in situations like these can cause false-positives (see #7258)

mypy/typeshed/stdlib/_ctypes.pyi

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ RTLD_LOCAL: int
2222
if sys.version_info >= (3, 11):
2323
CTYPES_MAX_ARGCOUNT: int
2424

25+
if sys.version_info >= (3, 12):
26+
SIZEOF_TIME_T: int
27+
2528
if sys.platform == "win32":
2629
# Description, Source, HelpFile, HelpContext, scode
2730
_COMError_Details: TypeAlias = tuple[str | None, str | None, str | None, int | None, int | None]
@@ -148,7 +151,11 @@ class Array(Generic[_CT], _CData):
148151
def _type_(self) -> type[_CT]: ...
149152
@_type_.setter
150153
def _type_(self, value: type[_CT]) -> None: ...
151-
raw: bytes # Note: only available if _CT == c_char
154+
# Note: only available if _CT == c_char
155+
@property
156+
def raw(self) -> bytes: ...
157+
@raw.setter
158+
def raw(self, value: ReadableBuffer) -> None: ...
152159
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
153160
# TODO These methods cannot be annotated correctly at the moment.
154161
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT

mypy/typeshed/stdlib/_socket.pyi

+25
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,28 @@ if sys.platform != "win32" or sys.version_info >= (3, 8):
692692
def if_nameindex() -> list[tuple[int, str]]: ...
693693
def if_nametoindex(__name: str) -> int: ...
694694
def if_indextoname(__index: int) -> str: ...
695+
696+
if sys.version_info >= (3, 12):
697+
IP_PKTINFO: int
698+
IP_UNBLOCK_SOURCE: int
699+
IP_BLOCK_SOURCE: int
700+
IP_ADD_SOURCE_MEMBERSHIP: int
701+
IP_DROP_SOURCE_MEMBERSHIP: int
702+
if sys.platform == "win32":
703+
AF_HYPERV: int
704+
HV_PROTOCOL_RAW: int
705+
HVSOCKET_CONNECT_TIMEOUT: int
706+
HVSOCKET_CONNECT_TIMEOUT_MAX: int
707+
HVSOCKET_CONNECTED_SUSPEND: int
708+
HVSOCKET_ADDRESS_FLAG_PASSTHRU: int
709+
HV_GUID_ZERO: str
710+
HV_GUID_WILDCARD: str
711+
HV_GUID_BROADCAST: str
712+
HV_GUID_CHILDREN: str
713+
HV_GUID_LOOPBACK: str
714+
HV_GUID_PARENT: str
715+
else:
716+
ETHERTYPE_ARP: int
717+
ETHERTYPE_IP: int
718+
ETHERTYPE_IPV6: int
719+
ETHERTYPE_VLAN: int

mypy/typeshed/stdlib/_thread.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ if sys.version_info >= (3, 8):
4343
@property
4444
def thread(self) -> Thread | None: ...
4545
_excepthook: Callable[[_ExceptHookArgs], Any]
46+
47+
if sys.version_info >= (3, 12):
48+
def daemon_threads_allowed() -> bool: ...

mypy/typeshed/stdlib/_winapi.pyi

+31
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ if sys.platform == "win32":
137137
LCMAP_TRADITIONAL_CHINESE: int
138138
LCMAP_UPPERCASE: int
139139

140+
if sys.version_info >= (3, 12):
141+
COPYFILE2_CALLBACK_CHUNK_STARTED: Literal[1]
142+
COPYFILE2_CALLBACK_CHUNK_FINISHED: Literal[2]
143+
COPYFILE2_CALLBACK_STREAM_STARTED: Literal[3]
144+
COPYFILE2_CALLBACK_STREAM_FINISHED: Literal[4]
145+
COPYFILE2_CALLBACK_POLL_CONTINUE: Literal[5]
146+
COPYFILE2_CALLBACK_ERROR: Literal[6]
147+
148+
COPYFILE2_PROGRESS_CONTINUE: Literal[0]
149+
COPYFILE2_PROGRESS_CANCEL: Literal[1]
150+
COPYFILE2_PROGRESS_STOP: Literal[2]
151+
COPYFILE2_PROGRESS_QUIET: Literal[3]
152+
COPYFILE2_PROGRESS_PAUSE: Literal[4]
153+
154+
COPY_FILE_FAIL_IF_EXISTS: Literal[0x1]
155+
COPY_FILE_RESTARTABLE: Literal[0x2]
156+
COPY_FILE_OPEN_SOURCE_FOR_WRITE: Literal[0x4]
157+
COPY_FILE_ALLOW_DECRYPTED_DESTINATION: Literal[0x8]
158+
COPY_FILE_COPY_SYMLINK: Literal[0x800]
159+
COPY_FILE_NO_BUFFERING: Literal[0x1000]
160+
COPY_FILE_REQUEST_SECURITY_PRIVILEGES: Literal[0x2000]
161+
COPY_FILE_RESUME_FROM_PAUSE: Literal[0x4000]
162+
COPY_FILE_NO_OFFLOAD: Literal[0x40000]
163+
COPY_FILE_REQUEST_COMPRESSED_TRAFFIC: Literal[0x10000000]
164+
165+
ERROR_ACCESS_DENIED: Literal[5]
166+
ERROR_PRIVILEGE_NOT_HELD: Literal[1314]
167+
140168
def CloseHandle(__handle: int) -> None: ...
141169
@overload
142170
def ConnectNamedPipe(handle: int, overlapped: Literal[True]) -> Overlapped: ...
@@ -224,3 +252,6 @@ if sys.platform == "win32":
224252
def GetOverlappedResult(self, __wait: bool) -> tuple[int, int]: ...
225253
def cancel(self) -> None: ...
226254
def getbuffer(self) -> bytes | None: ...
255+
256+
if sys.version_info >= (3, 12):
257+
def CopyFile2(existing_file_name: str, new_file_name: str, flags: int, progress_routine: int | None = None) -> int: ...

mypy/typeshed/stdlib/argparse.pyi

+38-12
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ class _ActionsContainer:
9797
version: str = ...,
9898
**kwargs: Any,
9999
) -> Action: ...
100-
def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ...
101-
def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ...
100+
def add_argument_group(
101+
self,
102+
title: str | None = None,
103+
description: str | None = None,
104+
*,
105+
prefix_chars: str = ...,
106+
argument_default: Any = ...,
107+
conflict_handler: str = ...,
108+
) -> _ArgumentGroup: ...
109+
def add_mutually_exclusive_group(self, *, required: bool = False) -> _MutuallyExclusiveGroup: ...
102110
def _add_action(self, action: _ActionT) -> _ActionT: ...
103111
def _remove_action(self, action: Action) -> None: ...
104112
def _add_container_actions(self, container: _ActionsContainer) -> None: ...
@@ -161,9 +169,9 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
161169
add_help: bool = True,
162170
allow_abbrev: bool = True,
163171
) -> None: ...
164-
# Ignore errors about overlapping overloads
172+
165173
@overload
166-
def parse_args(self, args: Sequence[str] | None = None, namespace: None = None) -> Namespace: ... # type: ignore[misc]
174+
def parse_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ... # type: ignore[misc]
167175
@overload
168176
def parse_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
169177
@overload
@@ -201,16 +209,27 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
201209
def print_help(self, file: IO[str] | None = None) -> None: ...
202210
def format_usage(self) -> str: ...
203211
def format_help(self) -> str: ...
204-
def parse_known_args(
205-
self, args: Sequence[str] | None = None, namespace: Namespace | None = None
206-
) -> tuple[Namespace, list[str]]: ...
212+
@overload
213+
def parse_known_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
214+
@overload
215+
def parse_known_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
216+
@overload
217+
def parse_known_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
207218
def convert_arg_line_to_args(self, arg_line: str) -> list[str]: ...
208219
def exit(self, status: int = 0, message: str | None = None) -> NoReturn: ...
209220
def error(self, message: str) -> NoReturn: ...
210-
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ...
211-
def parse_known_intermixed_args(
212-
self, args: Sequence[str] | None = None, namespace: Namespace | None = None
213-
) -> tuple[Namespace, list[str]]: ...
221+
@overload
222+
def parse_intermixed_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> Namespace: ... # type: ignore[misc]
223+
@overload
224+
def parse_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> _N: ...
225+
@overload
226+
def parse_intermixed_args(self, *, namespace: _N) -> _N: ...
227+
@overload
228+
def parse_known_intermixed_args(self, args: Sequence[str] | None = None, namespace: Namespace | None = None) -> tuple[Namespace, list[str]]: ... # type: ignore[misc]
229+
@overload
230+
def parse_known_intermixed_args(self, args: Sequence[str] | None, namespace: _N) -> tuple[_N, list[str]]: ...
231+
@overload
232+
def parse_known_intermixed_args(self, *, namespace: _N) -> tuple[_N, list[str]]: ...
214233
# undocumented
215234
def _get_optional_actions(self) -> list[Action]: ...
216235
def _get_positional_actions(self) -> list[Action]: ...
@@ -350,7 +369,14 @@ class _ArgumentGroup(_ActionsContainer):
350369
title: str | None
351370
_group_actions: list[Action]
352371
def __init__(
353-
self, container: _ActionsContainer, title: str | None = None, description: str | None = None, **kwargs: Any
372+
self,
373+
container: _ActionsContainer,
374+
title: str | None = None,
375+
description: str | None = None,
376+
*,
377+
prefix_chars: str = ...,
378+
argument_default: Any = ...,
379+
conflict_handler: str = ...,
354380
) -> None: ...
355381

356382
# undocumented

mypy/typeshed/stdlib/ast.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from _ast import *
44
from _typeshed import ReadableBuffer, Unused
55
from collections.abc import Iterator
6-
from typing import Any, TypeVar, overload
6+
from typing import Any, TypeVar as _TypeVar, overload
77
from typing_extensions import Literal
88

99
if sys.version_info >= (3, 8):
@@ -168,7 +168,7 @@ class NodeTransformer(NodeVisitor):
168168
# The usual return type is AST | None, but Iterable[AST]
169169
# is also allowed in some cases -- this needs to be mapped.
170170

171-
_T = TypeVar("_T", bound=AST)
171+
_T = _TypeVar("_T", bound=AST)
172172

173173
if sys.version_info >= (3, 8):
174174
@overload

0 commit comments

Comments
 (0)