Skip to content

Commit

Permalink
Sync typeshed (#13457)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatyping authored Aug 20, 2022
1 parent e6a0527 commit 4d4326a
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 61 deletions.
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/_threading_local.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ class _localimpl:
class local:
def __getattribute__(self, name: str) -> Any: ...
def __setattr__(self, name: str, value: Any) -> None: ...
def __delattr__(self, name: str) -> None: ...
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if sys.platform == "win32":
WAIT_OBJECT_0: Literal[0]
WAIT_TIMEOUT: Literal[258]

if sys.version_info >= (3, 11):
if sys.version_info >= (3, 10):
LOCALE_NAME_INVARIANT: str
LOCALE_NAME_MAX_LENGTH: int
LOCALE_NAME_SYSTEM_DEFAULT: str
Expand Down Expand Up @@ -181,7 +181,7 @@ if sys.platform == "win32":
def GetVersion() -> int: ...
def OpenProcess(__desired_access: int, __inherit_handle: bool, __process_id: int) -> int: ...
def PeekNamedPipe(__handle: int, __size: int = ...) -> tuple[int, int] | tuple[bytes, int, int]: ...
if sys.version_info >= (3, 11):
if sys.version_info >= (3, 10):
def LCMapStringEx(locale: str, flags: int, src: str) -> str: ...

@overload
Expand Down
50 changes: 48 additions & 2 deletions mypy/typeshed/stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
_optionals: _ArgumentGroup
_subparsers: _ArgumentGroup | None

# Note: the constructor arguments are also used in _SubParsersAction.add_parser.
if sys.version_info >= (3, 9):
def __init__(
self,
Expand Down Expand Up @@ -458,8 +459,53 @@ class _SubParsersAction(Action, Generic[_ArgumentParserT]):
help: str | None = ...,
metavar: str | tuple[str, ...] | None = ...,
) -> None: ...
# TODO: Type keyword args properly.
def add_parser(self, name: str, **kwargs: Any) -> _ArgumentParserT: ...

# Note: `add_parser` accepts all kwargs of `ArgumentParser.__init__`. It also
# accepts its own `help` and `aliases` kwargs.
if sys.version_info >= (3, 9):
def add_parser(
self,
name: str,
*,
help: str | None = ...,
aliases: Sequence[str] = ...,
# Kwargs from ArgumentParser constructor
prog: str | None = ...,
usage: str | None = ...,
description: str | None = ...,
epilog: str | None = ...,
parents: Sequence[_ArgumentParserT] = ...,
formatter_class: _FormatterClass = ...,
prefix_chars: str = ...,
fromfile_prefix_chars: str | None = ...,
argument_default: Any = ...,
conflict_handler: str = ...,
add_help: bool = ...,
allow_abbrev: bool = ...,
exit_on_error: bool = ...,
) -> _ArgumentParserT: ...
else:
def add_parser(
self,
name: str,
*,
help: str | None = ...,
aliases: Sequence[str] = ...,
# Kwargs from ArgumentParser constructor
prog: str | None = ...,
usage: str | None = ...,
description: str | None = ...,
epilog: str | None = ...,
parents: Sequence[_ArgumentParserT] = ...,
formatter_class: _FormatterClass = ...,
prefix_chars: str = ...,
fromfile_prefix_chars: str | None = ...,
argument_default: Any = ...,
conflict_handler: str = ...,
add_help: bool = ...,
allow_abbrev: bool = ...,
) -> _ArgumentParserT: ...

def _get_subactions(self) -> list[Action]: ...

# undocumented
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/mixins.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import threading
from typing import NoReturn
from typing_extensions import Never

_global_lock: threading.Lock

class _LoopBoundMixin:
if sys.version_info < (3, 11):
def __init__(self, *, loop: NoReturn = ...) -> None: ...
def __init__(self, *, loop: Never = ...) -> None: ...
8 changes: 2 additions & 6 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ class int:
@overload
def __pow__(self, __x: int, __modulo: None = ...) -> Any: ...
@overload
def __pow__(self, __x: int, __modulo: Literal[0]) -> NoReturn: ...
@overload
def __pow__(self, __x: int, __modulo: int) -> int: ...
def __rpow__(self, __x: int, __mod: int | None = ...) -> Any: ...
def __and__(self, __n: int) -> int: ...
Expand Down Expand Up @@ -1457,8 +1455,8 @@ _SupportsSomeKindOfPow = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs a
)

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

else:
@overload
def pow(__base: int, __exp: int, __mod: Literal[0]) -> NoReturn: ...
@overload
def pow(__base: int, __exp: int, __mod: int) -> int: ...
@overload
Expand Down
14 changes: 14 additions & 0 deletions mypy/typeshed/stdlib/socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ if sys.platform == "linux":
CAN_RAW_RECV_OWN_MSGS as CAN_RAW_RECV_OWN_MSGS,
CAN_RTR_FLAG as CAN_RTR_FLAG,
CAN_SFF_MASK as CAN_SFF_MASK,
NETLINK_ARPD as NETLINK_ARPD,
NETLINK_CRYPTO as NETLINK_CRYPTO,
NETLINK_DNRTMSG as NETLINK_DNRTMSG,
NETLINK_FIREWALL as NETLINK_FIREWALL,
NETLINK_IP6_FW as NETLINK_IP6_FW,
NETLINK_NFLOG as NETLINK_NFLOG,
NETLINK_ROUTE as NETLINK_ROUTE,
NETLINK_ROUTE6 as NETLINK_ROUTE6,
NETLINK_SKIP as NETLINK_SKIP,
NETLINK_TAPBASE as NETLINK_TAPBASE,
NETLINK_TCPDIAG as NETLINK_TCPDIAG,
NETLINK_USERSOCK as NETLINK_USERSOCK,
NETLINK_W1 as NETLINK_W1,
NETLINK_XFRM as NETLINK_XFRM,
PACKET_BROADCAST as PACKET_BROADCAST,
PACKET_FASTROUTE as PACKET_FASTROUTE,
PACKET_HOST as PACKET_HOST,
Expand Down
9 changes: 4 additions & 5 deletions mypy/typeshed/stdlib/socketserver.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class BaseServer:
def close_request(self, request: _RequestType) -> None: ... # undocumented

class TCPServer(BaseServer):
allow_reuse_port: bool
if sys.version_info >= (3, 11):
allow_reuse_port: bool
request_queue_size: int
def __init__(
self: Self,
Expand All @@ -80,11 +81,9 @@ class TCPServer(BaseServer):
) -> None: ...
def get_request(self) -> tuple[_socket, Any]: ...

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

if sys.platform != "win32":
class UnixStreamServer(BaseServer):
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/sqlite3/dbapi2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def enable_callback_tracebacks(__enable: bool) -> None: ...
# takes a pos-or-keyword argument because there is a C wrapper
def enable_shared_cache(enable: int) -> None: ...

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

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/sysconfig.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __all__ = [
"parse_config_h",
]

def get_config_var(name: str) -> str | None: ...
def get_config_var(name: str) -> Any: ...
@overload
def get_config_vars() -> dict[str, Any]: ...
@overload
Expand Down
17 changes: 9 additions & 8 deletions mypy/typeshed/stdlib/typing.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _typeshed
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from contextlib import AbstractAsyncContextManager, AbstractContextManager
Expand All @@ -17,7 +18,7 @@ from types import (
TracebackType,
WrapperDescriptorType,
)
from typing_extensions import ParamSpec as _ParamSpec, final as _final
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec, final as _final

__all__ = [
"AbstractSet",
Expand Down Expand Up @@ -790,16 +791,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
__required_keys__: ClassVar[frozenset[str]]
__optional_keys__: ClassVar[frozenset[str]]
def copy(self: _typeshed.Self) -> _typeshed.Self: ...
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
# Using Never so that only calls using mypy plugin hook that specialize the signature
# can go through.
def setdefault(self, k: NoReturn, default: object) -> object: ...
def setdefault(self, k: _Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def pop(self, k: _Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, __m: _T) -> None: ...
def __delitem__(self, k: NoReturn) -> None: ...
def items(self) -> ItemsView[str, object]: ...
def keys(self) -> KeysView[str]: ...
def values(self) -> ValuesView[object]: ...
def __delitem__(self, k: _Never) -> None: ...
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
if sys.version_info >= (3, 9):
def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
Expand Down
22 changes: 10 additions & 12 deletions mypy/typeshed/stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _typeshed
import abc
import collections
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import IdentityFunction
from collections.abc import Iterable
from typing import ( # noqa: Y022,Y027,Y039
Expand All @@ -20,16 +21,13 @@ from typing import ( # noqa: Y022,Y027,Y039
Counter as Counter,
DefaultDict as DefaultDict,
Deque as Deque,
ItemsView,
KeysView,
Mapping,
NewType as NewType,
NoReturn as NoReturn,
Sequence,
Text as Text,
Type as Type,
TypeVar,
ValuesView,
_Alias,
overload as overload,
type_check_only,
Expand Down Expand Up @@ -129,16 +127,16 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
__optional_keys__: ClassVar[frozenset[str]]
__total__: ClassVar[bool]
def copy(self: _typeshed.Self) -> _typeshed.Self: ...
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
# Using Never so that only calls using mypy plugin hook that specialize the signature
# can go through.
def setdefault(self, k: NoReturn, default: object) -> object: ...
def setdefault(self, k: Never, default: object) -> object: ...
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
def update(self: _T, __m: _T) -> None: ...
def items(self) -> ItemsView[str, object]: ...
def keys(self) -> KeysView[str]: ...
def values(self) -> ValuesView[object]: ...
def __delitem__(self, k: NoReturn) -> None: ...
def items(self) -> dict_items[str, object]: ...
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
def __delitem__(self, k: Never) -> None: ...
if sys.version_info >= (3, 9):
def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
Expand Down Expand Up @@ -223,9 +221,9 @@ if sys.version_info >= (3, 11):
)
else:
Self: _SpecialForm
Never: _SpecialForm
Never: _SpecialForm = ...
def reveal_type(__obj: _T) -> _T: ...
def assert_never(__arg: NoReturn) -> NoReturn: ...
def assert_never(__arg: Never) -> Never: ...
def assert_type(__val: _T, __typ: Any) -> _T: ...
def clear_overloads() -> None: ...
def get_overloads(func: Callable[..., object]) -> Sequence[Callable[..., object]]: ...
Expand Down
22 changes: 11 additions & 11 deletions mypy/typeshed/stdlib/xml/dom/minidom.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Node(xml.dom.Node):
def __exit__(self, et, ev, tb) -> None: ...

class DocumentFragment(Node):
nodeType: Any
nodeType: int
nodeName: str
nodeValue: Any
attributes: Any
Expand All @@ -59,7 +59,7 @@ class DocumentFragment(Node):

class Attr(Node):
name: str
nodeType: Any
nodeType: int
attributes: Any
specified: bool
ownerElement: Any
Expand Down Expand Up @@ -114,7 +114,7 @@ class TypeInfo:
def __init__(self, namespace, name) -> None: ...

class Element(Node):
nodeType: Any
nodeType: int
nodeValue: Any
schemaType: Any
parentNode: Any
Expand Down Expand Up @@ -165,7 +165,7 @@ class Childless:
def replaceChild(self, newChild, oldChild) -> None: ...

class ProcessingInstruction(Childless, Node):
nodeType: Any
nodeType: int
target: Any
data: Any
def __init__(self, target, data) -> None: ...
Expand All @@ -189,7 +189,7 @@ class CharacterData(Childless, Node):
def length(self) -> int: ...

class Text(CharacterData):
nodeType: Any
nodeType: int
nodeName: str
attributes: Any
data: Any
Expand All @@ -202,13 +202,13 @@ class Text(CharacterData):
def wholeText(self) -> str: ...

class Comment(CharacterData):
nodeType: Any
nodeType: int
nodeName: str
def __init__(self, data) -> None: ...
def writexml(self, writer, indent: str = ..., addindent: str = ..., newl: str = ...) -> None: ...

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

Expand All @@ -231,7 +231,7 @@ class Identified:
systemId: Any

class DocumentType(Identified, Childless, Node):
nodeType: Any
nodeType: int
nodeValue: Any
name: Any
internalSubset: Any
Expand All @@ -244,7 +244,7 @@ class DocumentType(Identified, Childless, Node):

class Entity(Identified, Node):
attributes: Any
nodeType: Any
nodeType: int
nodeValue: Any
actualEncoding: Any
encoding: Any
Expand All @@ -259,7 +259,7 @@ class Entity(Identified, Node):
def replaceChild(self, newChild, oldChild) -> None: ...

class Notation(Identified, Childless, Node):
nodeType: Any
nodeType: int
nodeValue: Any
nodeName: Any
def __init__(self, name, publicId, systemId) -> None: ...
Expand All @@ -282,7 +282,7 @@ class ElementInfo:

class Document(Node, DocumentLS):
implementation: Any
nodeType: Any
nodeType: int
nodeName: str
nodeValue: Any
attributes: Any
Expand Down
Loading

0 comments on commit 4d4326a

Please sign in to comment.