Skip to content

Commit 4d4326a

Browse files
authored
Sync typeshed (#13457)
Source commit: python/typeshed@5435ed7
1 parent e6a0527 commit 4d4326a

File tree

14 files changed

+118
-61
lines changed

14 files changed

+118
-61
lines changed

mypy/typeshed/stdlib/_threading_local.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ class _localimpl:
1414
class local:
1515
def __getattribute__(self, name: str) -> Any: ...
1616
def __setattr__(self, name: str, value: Any) -> None: ...
17+
def __delattr__(self, name: str) -> None: ...

mypy/typeshed/stdlib/_winapi.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if sys.platform == "win32":
106106
WAIT_OBJECT_0: Literal[0]
107107
WAIT_TIMEOUT: Literal[258]
108108

109-
if sys.version_info >= (3, 11):
109+
if sys.version_info >= (3, 10):
110110
LOCALE_NAME_INVARIANT: str
111111
LOCALE_NAME_MAX_LENGTH: int
112112
LOCALE_NAME_SYSTEM_DEFAULT: str
@@ -181,7 +181,7 @@ if sys.platform == "win32":
181181
def GetVersion() -> int: ...
182182
def OpenProcess(__desired_access: int, __inherit_handle: bool, __process_id: int) -> int: ...
183183
def PeekNamedPipe(__handle: int, __size: int = ...) -> tuple[int, int] | tuple[bytes, int, int]: ...
184-
if sys.version_info >= (3, 11):
184+
if sys.version_info >= (3, 10):
185185
def LCMapStringEx(locale: str, flags: int, src: str) -> str: ...
186186

187187
@overload

mypy/typeshed/stdlib/argparse.pyi

+48-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
127127
_optionals: _ArgumentGroup
128128
_subparsers: _ArgumentGroup | None
129129

130+
# Note: the constructor arguments are also used in _SubParsersAction.add_parser.
130131
if sys.version_info >= (3, 9):
131132
def __init__(
132133
self,
@@ -458,8 +459,53 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
458459
help: str | None = ...,
459460
metavar: str | tuple[str, ...] | None = ...,
460461
) -> None: ...
461-
# TODO: Type keyword args properly.
462-
def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ...
462+
463+
# Note: `add_parser` accepts all kwargs of `ArgumentParser.__init__`. It also
464+
# accepts its own `help` and `aliases` kwargs.
465+
if sys.version_info >= (3, 9):
466+
def add_parser(
467+
self,
468+
name: str,
469+
*,
470+
help: str | None = ...,
471+
aliases: Sequence[str] = ...,
472+
# Kwargs from ArgumentParser constructor
473+
prog: str | None = ...,
474+
usage: str | None = ...,
475+
description: str | None = ...,
476+
epilog: str | None = ...,
477+
parents: Sequence[_ArgumentParserT] = ...,
478+
formatter_class: _FormatterClass = ...,
479+
prefix_chars: str = ...,
480+
fromfile_prefix_chars: str | None = ...,
481+
argument_default: Any = ...,
482+
conflict_handler: str = ...,
483+
add_help: bool = ...,
484+
allow_abbrev: bool = ...,
485+
exit_on_error: bool = ...,
486+
) -> _ArgumentParserT: ...
487+
else:
488+
def add_parser(
489+
self,
490+
name: str,
491+
*,
492+
help: str | None = ...,
493+
aliases: Sequence[str] = ...,
494+
# Kwargs from ArgumentParser constructor
495+
prog: str | None = ...,
496+
usage: str | None = ...,
497+
description: str | None = ...,
498+
epilog: str | None = ...,
499+
parents: Sequence[_ArgumentParserT] = ...,
500+
formatter_class: _FormatterClass = ...,
501+
prefix_chars: str = ...,
502+
fromfile_prefix_chars: str | None = ...,
503+
argument_default: Any = ...,
504+
conflict_handler: str = ...,
505+
add_help: bool = ...,
506+
allow_abbrev: bool = ...,
507+
) -> _ArgumentParserT: ...
508+
463509
def _get_subactions(self) -> list[Action]: ...
464510

465511
# undocumented
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import sys
22
import threading
3-
from typing import NoReturn
3+
from typing_extensions import Never
44

55
_global_lock: threading.Lock
66

77
class _LoopBoundMixin:
88
if sys.version_info < (3, 11):
9-
def __init__(self, *, loop: NoReturn = ...) -> None: ...
9+
def __init__(self, *, loop: Never = ...) -> None: ...

mypy/typeshed/stdlib/builtins.pyi

+2-6
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ class int:
266266
@overload
267267
def __pow__(self, __x: int, __modulo: None = ...) -> Any: ...
268268
@overload
269-
def __pow__(self, __x: int, __modulo: Literal[0]) -> NoReturn: ...
270-
@overload
271269
def __pow__(self, __x: int, __modulo: int) -> int: ...
272270
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ...
273271
def __and__(self, __n: int) -> int: ...
@@ -1457,8 +1455,8 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a
14571455
)
14581456

14591457
if sys.version_info >= (3, 8):
1460-
@overload
1461-
def pow(base: int, exp: int, mod: Literal[0]) -> NoReturn: ...
1458+
# TODO: `pow(int, int, Literal[0])` fails at runtime,
1459+
# but adding a `NoReturn` overload isn't a good solution for expressing that (see #8566).
14621460
@overload
14631461
def pow(base: int, exp: int, mod: int) -> int: ...
14641462
@overload
@@ -1496,8 +1494,6 @@ if sys.version_info >= (3, 8):
14961494
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = ...) -> complex: ...
14971495

14981496
else:
1499-
@overload
1500-
def pow(__base: int, __exp: int, __mod: Literal[0]) -> NoReturn: ...
15011497
@overload
15021498
def pow(__base: int, __exp: int, __mod: int) -> int: ...
15031499
@overload

mypy/typeshed/stdlib/socket.pyi

+14
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ if sys.platform == "linux":
297297
CAN_RAW_RECV_OWN_MSGS as CAN_RAW_RECV_OWN_MSGS,
298298
CAN_RTR_FLAG as CAN_RTR_FLAG,
299299
CAN_SFF_MASK as CAN_SFF_MASK,
300+
NETLINK_ARPD as NETLINK_ARPD,
301+
NETLINK_CRYPTO as NETLINK_CRYPTO,
302+
NETLINK_DNRTMSG as NETLINK_DNRTMSG,
303+
NETLINK_FIREWALL as NETLINK_FIREWALL,
304+
NETLINK_IP6_FW as NETLINK_IP6_FW,
305+
NETLINK_NFLOG as NETLINK_NFLOG,
306+
NETLINK_ROUTE as NETLINK_ROUTE,
307+
NETLINK_ROUTE6 as NETLINK_ROUTE6,
308+
NETLINK_SKIP as NETLINK_SKIP,
309+
NETLINK_TAPBASE as NETLINK_TAPBASE,
310+
NETLINK_TCPDIAG as NETLINK_TCPDIAG,
311+
NETLINK_USERSOCK as NETLINK_USERSOCK,
312+
NETLINK_W1 as NETLINK_W1,
313+
NETLINK_XFRM as NETLINK_XFRM,
300314
PACKET_BROADCAST as PACKET_BROADCAST,
301315
PACKET_FASTROUTE as PACKET_FASTROUTE,
302316
PACKET_HOST as PACKET_HOST,

mypy/typeshed/stdlib/socketserver.pyi

+4-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class BaseServer:
7070
def close_request(self, request: _RequestType) -> None: ... # undocumented
7171

7272
class TCPServer(BaseServer):
73-
allow_reuse_port: bool
73+
if sys.version_info >= (3, 11):
74+
allow_reuse_port: bool
7475
request_queue_size: int
7576
def __init__(
7677
self: Self,
@@ -80,11 +81,9 @@ class TCPServer(BaseServer):
8081
) -> None: ...
8182
def get_request(self) -> tuple[_socket, Any]: ...
8283

83-
class UDPServer(BaseServer):
84-
if sys.version_info >= (3, 11):
85-
allow_reuse_port: bool
84+
class UDPServer(TCPServer):
8685
max_packet_size: ClassVar[int]
87-
def get_request(self) -> tuple[tuple[bytes, _socket], Any]: ...
86+
def get_request(self) -> tuple[tuple[bytes, _socket], Any]: ... # type: ignore[override]
8887

8988
if sys.platform != "win32":
9089
class UnixStreamServer(BaseServer):

mypy/typeshed/stdlib/sqlite3/dbapi2.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def enable_callback_tracebacks(__enable: bool) -> None: ...
217217
# takes a pos-or-keyword argument because there is a C wrapper
218218
def enable_shared_cache(enable: int) -> None: ...
219219

220-
if sys.version_info >= (3, 11):
220+
if sys.version_info >= (3, 10):
221221
def register_adapter(__type: type[_T], __adapter: _Adapter[_T]) -> None: ...
222222
def register_converter(__typename: str, __converter: _Converter) -> None: ...
223223

mypy/typeshed/stdlib/sysconfig.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ __all__ = [
1616
"parse_config_h",
1717
]
1818

19-
def get_config_var(name: str) -> str | None: ...
19+
def get_config_var(name: str) -> Any: ...
2020
@overload
2121
def get_config_vars() -> dict[str, Any]: ...
2222
@overload

mypy/typeshed/stdlib/typing.pyi

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _typeshed
22
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
33
import sys
4+
from _collections_abc import dict_items, dict_keys, dict_values
45
from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem
56
from abc import ABCMeta, abstractmethod
67
from contextlib import AbstractAsyncContextManager, AbstractContextManager
@@ -17,7 +18,7 @@ from types import (
1718
TracebackType,
1819
WrapperDescriptorType,
1920
)
20-
from typing_extensions import ParamSpec as _ParamSpec, final as _final
21+
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec, final as _final
2122

2223
__all__ = [
2324
"AbstractSet",
@@ -790,16 +791,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
790791
__required_keys__: ClassVar[frozenset[str]]
791792
__optional_keys__: ClassVar[frozenset[str]]
792793
def copy(self: _typeshed.Self) -> _typeshed.Self: ...
793-
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
794+
# Using Never so that only calls using mypy plugin hook that specialize the signature
794795
# can go through.
795-
def setdefault(self, k: NoReturn, default: object) -> object: ...
796+
def setdefault(self, k: _Never, default: object) -> object: ...
796797
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
797-
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
798+
def pop(self, k: _Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
798799
def update(self: _T, __m: _T) -> None: ...
799-
def __delitem__(self, k: NoReturn) -> None: ...
800-
def items(self) -> ItemsView[str, object]: ...
801-
def keys(self) -> KeysView[str]: ...
802-
def values(self) -> ValuesView[object]: ...
800+
def __delitem__(self, k: _Never) -> None: ...
801+
def items(self) -> dict_items[str, object]: ...
802+
def keys(self) -> dict_keys[str, object]: ...
803+
def values(self) -> dict_values[str, object]: ...
803804
if sys.version_info >= (3, 9):
804805
def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
805806
def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...

mypy/typeshed/stdlib/typing_extensions.pyi

+10-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _typeshed
22
import abc
33
import collections
44
import sys
5+
from _collections_abc import dict_items, dict_keys, dict_values
56
from _typeshed import IdentityFunction
67
from collections.abc import Iterable
78
from typing import ( # noqa: Y022,Y027,Y039
@@ -20,16 +21,13 @@ from typing import ( # noqa: Y022,Y027,Y039
2021
Counter as Counter,
2122
DefaultDict as DefaultDict,
2223
Deque as Deque,
23-
ItemsView,
24-
KeysView,
2524
Mapping,
2625
NewType as NewType,
2726
NoReturn as NoReturn,
2827
Sequence,
2928
Text as Text,
3029
Type as Type,
3130
TypeVar,
32-
ValuesView,
3331
_Alias,
3432
overload as overload,
3533
type_check_only,
@@ -129,16 +127,16 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
129127
__optional_keys__: ClassVar[frozenset[str]]
130128
__total__: ClassVar[bool]
131129
def copy(self: _typeshed.Self) -> _typeshed.Self: ...
132-
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
130+
# Using Never so that only calls using mypy plugin hook that specialize the signature
133131
# can go through.
134-
def setdefault(self, k: NoReturn, default: object) -> object: ...
132+
def setdefault(self, k: Never, default: object) -> object: ...
135133
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
136-
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
134+
def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
137135
def update(self: _T, __m: _T) -> None: ...
138-
def items(self) -> ItemsView[str, object]: ...
139-
def keys(self) -> KeysView[str]: ...
140-
def values(self) -> ValuesView[object]: ...
141-
def __delitem__(self, k: NoReturn) -> None: ...
136+
def items(self) -> dict_items[str, object]: ...
137+
def keys(self) -> dict_keys[str, object]: ...
138+
def values(self) -> dict_values[str, object]: ...
139+
def __delitem__(self, k: Never) -> None: ...
142140
if sys.version_info >= (3, 9):
143141
def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
144142
def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
@@ -223,9 +221,9 @@ if sys.version_info >= (3, 11):
223221
)
224222
else:
225223
Self: _SpecialForm
226-
Never: _SpecialForm
224+
Never: _SpecialForm = ...
227225
def reveal_type(__obj: _T) -> _T: ...
228-
def assert_never(__arg: NoReturn) -> NoReturn: ...
226+
def assert_never(__arg: Never) -> Never: ...
229227
def assert_type(__val: _T, __typ: Any) -> _T: ...
230228
def clear_overloads() -> None: ...
231229
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...

mypy/typeshed/stdlib/xml/dom/minidom.pyi

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Node(xml.dom.Node):
4949
def __exit__(self, et, ev, tb) -> None: ...
5050

5151
class DocumentFragment(Node):
52-
nodeType: Any
52+
nodeType: int
5353
nodeName: str
5454
nodeValue: Any
5555
attributes: Any
@@ -59,7 +59,7 @@ class DocumentFragment(Node):
5959

6060
class Attr(Node):
6161
name: str
62-
nodeType: Any
62+
nodeType: int
6363
attributes: Any
6464
specified: bool
6565
ownerElement: Any
@@ -114,7 +114,7 @@ class TypeInfo:
114114
def __init__(self, namespace, name) -> None: ...
115115

116116
class Element(Node):
117-
nodeType: Any
117+
nodeType: int
118118
nodeValue: Any
119119
schemaType: Any
120120
parentNode: Any
@@ -165,7 +165,7 @@ class Childless:
165165
def replaceChild(self, newChild, oldChild) -> None: ...
166166

167167
class ProcessingInstruction(Childless, Node):
168-
nodeType: Any
168+
nodeType: int
169169
target: Any
170170
data: Any
171171
def __init__(self, target, data) -> None: ...
@@ -189,7 +189,7 @@ class CharacterData(Childless, Node):
189189
def length(self) -> int: ...
190190

191191
class Text(CharacterData):
192-
nodeType: Any
192+
nodeType: int
193193
nodeName: str
194194
attributes: Any
195195
data: Any
@@ -202,13 +202,13 @@ class Text(CharacterData):
202202
def wholeText(self) -> str: ...
203203

204204
class Comment(CharacterData):
205-
nodeType: Any
205+
nodeType: int
206206
nodeName: str
207207
def __init__(self, data) -> None: ...
208208
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
209209

210210
class CDATASection(Text):
211-
nodeType: Any
211+
nodeType: int
212212
nodeName: str
213213
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...
214214

@@ -231,7 +231,7 @@ class Identified:
231231
systemId: Any
232232

233233
class DocumentType(Identified, Childless, Node):
234-
nodeType: Any
234+
nodeType: int
235235
nodeValue: Any
236236
name: Any
237237
internalSubset: Any
@@ -244,7 +244,7 @@ class DocumentType(Identified, Childless, Node):
244244

245245
class Entity(Identified, Node):
246246
attributes: Any
247-
nodeType: Any
247+
nodeType: int
248248
nodeValue: Any
249249
actualEncoding: Any
250250
encoding: Any
@@ -259,7 +259,7 @@ class Entity(Identified, Node):
259259
def replaceChild(self, newChild, oldChild) -> None: ...
260260

261261
class Notation(Identified, Childless, Node):
262-
nodeType: Any
262+
nodeType: int
263263
nodeValue: Any
264264
nodeName: Any
265265
def __init__(self, name, publicId, systemId) -> None: ...
@@ -282,7 +282,7 @@ class ElementInfo:
282282

283283
class Document(Node, DocumentLS):
284284
implementation: Any
285-
nodeType: Any
285+
nodeType: int
286286
nodeName: str
287287
nodeValue: Any
288288
attributes: Any

0 commit comments

Comments
 (0)