diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 678e68cca886..90970429ab8c 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -11,8 +11,8 @@ else: import tomli as tomllib -from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence, - TextIO, Tuple, Union) +from typing import (Any, Callable, Dict, List, Mapping, MutableMapping, Optional, Sequence, + TextIO, Tuple, Union, Iterable) from typing_extensions import Final, TypeAlias as _TypeAlias from mypy import defaults @@ -179,7 +179,8 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], if filename is not None: config_files: Tuple[str, ...] = (filename,) else: - config_files = tuple(map(os.path.expanduser, defaults.CONFIG_FILES)) + config_files_iter: Iterable[str] = map(os.path.expanduser, defaults.CONFIG_FILES) + config_files = tuple(config_files_iter) config_parser = configparser.RawConfigParser() diff --git a/mypy/typeshed/stdlib/@python2/itertools.pyi b/mypy/typeshed/stdlib/@python2/itertools.pyi index 6509213e1625..b07a911c3e20 100644 --- a/mypy/typeshed/stdlib/@python2/itertools.pyi +++ b/mypy/typeshed/stdlib/@python2/itertools.pyi @@ -22,7 +22,10 @@ class chain(Iterator[_T], Generic[_T]): def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ... def dropwhile(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... -def ifilter(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ... +@overload +def ifilter(predicate: None, iterable: Iterable[_T | None]) -> Iterator[_T]: ... +@overload +def ifilter(predicate: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... def ifilterfalse(predicate: Callable[[_T], Any] | None, iterable: Iterable[_T]) -> Iterator[_T]: ... @overload def groupby(iterable: Iterable[_T], key: None = ...) -> Iterator[tuple[_T, Iterator[_T]]]: ... diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi index 52941a0c5229..80fb06a228a7 100644 --- a/mypy/typeshed/stdlib/__future__.pyi +++ b/mypy/typeshed/stdlib/__future__.pyi @@ -1,9 +1,12 @@ import sys +from typing_extensions import TypeAlias + +_VersionInfo: TypeAlias = tuple[int, int, int, str, int] class _Feature: - def __init__(self, optionalRelease: sys._version_info, mandatoryRelease: sys._version_info, compiler_flag: int) -> None: ... - def getOptionalRelease(self) -> sys._version_info: ... - def getMandatoryRelease(self) -> sys._version_info: ... + def __init__(self, optionalRelease: _VersionInfo, mandatoryRelease: _VersionInfo | None, compiler_flag: int) -> None: ... + def getOptionalRelease(self) -> _VersionInfo: ... + def getMandatoryRelease(self) -> _VersionInfo | None: ... compiler_flag: int absolute_import: _Feature diff --git a/mypy/typeshed/stdlib/_ast.pyi b/mypy/typeshed/stdlib/_ast.pyi index 81cb9ffbf26e..c68e921babd0 100644 --- a/mypy/typeshed/stdlib/_ast.pyi +++ b/mypy/typeshed/stdlib/_ast.pyi @@ -7,7 +7,7 @@ if sys.version_info >= (3, 8): PyCF_TYPE_COMMENTS: Literal[4096] PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192] -_identifier: TypeAlias = str +_Identifier: TypeAlias = str class AST: if sys.version_info >= (3, 10): @@ -61,7 +61,7 @@ class stmt(AST): ... class FunctionDef(stmt): if sys.version_info >= (3, 10): __match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment") - name: _identifier + name: _Identifier args: arguments body: list[stmt] decorator_list: list[expr] @@ -70,7 +70,7 @@ class FunctionDef(stmt): class AsyncFunctionDef(stmt): if sys.version_info >= (3, 10): __match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment") - name: _identifier + name: _Identifier args: arguments body: list[stmt] decorator_list: list[expr] @@ -79,7 +79,7 @@ class AsyncFunctionDef(stmt): class ClassDef(stmt): if sys.version_info >= (3, 10): __match_args__ = ("name", "bases", "keywords", "body", "decorator_list") - name: _identifier + name: _Identifier bases: list[expr] keywords: list[keyword] body: list[stmt] @@ -194,19 +194,19 @@ class Import(stmt): class ImportFrom(stmt): if sys.version_info >= (3, 10): __match_args__ = ("module", "names", "level") - module: _identifier | None + module: _Identifier | None names: list[alias] level: int class Global(stmt): if sys.version_info >= (3, 10): __match_args__ = ("names",) - names: list[_identifier] + names: list[_Identifier] class Nonlocal(stmt): if sys.version_info >= (3, 10): __match_args__ = ("names",) - names: list[_identifier] + names: list[_Identifier] class Expr(stmt): if sys.version_info >= (3, 10): @@ -362,16 +362,16 @@ class Attribute(expr): if sys.version_info >= (3, 10): __match_args__ = ("value", "attr", "ctx") value: expr - attr: _identifier + attr: _Identifier ctx: expr_context if sys.version_info >= (3, 9): - _SliceT: TypeAlias = expr + _Slice: TypeAlias = expr else: class slice(AST): ... - _SliceT: TypeAlias = slice + _Slice: TypeAlias = slice -class Slice(_SliceT): +class Slice(_Slice): if sys.version_info >= (3, 10): __match_args__ = ("lower", "upper", "step") lower: expr | None @@ -389,7 +389,7 @@ class Subscript(expr): if sys.version_info >= (3, 10): __match_args__ = ("value", "slice", "ctx") value: expr - slice: _SliceT + slice: _Slice ctx: expr_context class Starred(expr): @@ -401,7 +401,7 @@ class Starred(expr): class Name(expr): if sys.version_info >= (3, 10): __match_args__ = ("id", "ctx") - id: _identifier + id: _Identifier ctx: expr_context class List(expr): @@ -479,7 +479,7 @@ class ExceptHandler(excepthandler): if sys.version_info >= (3, 10): __match_args__ = ("type", "name", "body") type: expr | None - name: _identifier | None + name: _Identifier | None body: list[stmt] class arguments(AST): @@ -497,20 +497,20 @@ class arguments(AST): class arg(AST): if sys.version_info >= (3, 10): __match_args__ = ("arg", "annotation", "type_comment") - arg: _identifier + arg: _Identifier annotation: expr | None class keyword(AST): if sys.version_info >= (3, 10): __match_args__ = ("arg", "value") - arg: _identifier | None + arg: _Identifier | None value: expr class alias(AST): if sys.version_info >= (3, 10): __match_args__ = ("name", "asname") - name: _identifier - asname: _identifier | None + name: _Identifier + asname: _Identifier | None class withitem(AST): if sys.version_info >= (3, 10): @@ -526,11 +526,11 @@ if sys.version_info >= (3, 10): class pattern(AST): ... # Without the alias, Pyright complains variables named pattern are recursively defined - _pattern: TypeAlias = pattern + _Pattern: TypeAlias = pattern class match_case(AST): __match_args__ = ("pattern", "guard", "body") - pattern: _pattern + pattern: _Pattern guard: expr | None body: list[stmt] @@ -548,25 +548,25 @@ if sys.version_info >= (3, 10): class MatchStar(pattern): __match_args__ = ("name",) - name: _identifier | None + name: _Identifier | None class MatchMapping(pattern): __match_args__ = ("keys", "patterns", "rest") keys: list[expr] patterns: list[pattern] - rest: _identifier | None + rest: _Identifier | None class MatchClass(pattern): __match_args__ = ("cls", "patterns", "kwd_attrs", "kwd_patterns") cls: expr patterns: list[pattern] - kwd_attrs: list[_identifier] + kwd_attrs: list[_Identifier] kwd_patterns: list[pattern] class MatchAs(pattern): __match_args__ = ("pattern", "name") - pattern: _pattern | None - name: _identifier | None + pattern: _Pattern | None + name: _Identifier | None class MatchOr(pattern): __match_args__ = ("patterns",) diff --git a/mypy/typeshed/stdlib/_codecs.pyi b/mypy/typeshed/stdlib/_codecs.pyi index 8fabf94d827e..9241ac6a7038 100644 --- a/mypy/typeshed/stdlib/_codecs.pyi +++ b/mypy/typeshed/stdlib/_codecs.pyi @@ -8,7 +8,7 @@ from typing_extensions import Literal, TypeAlias class _EncodingMap: def size(self) -> int: ... -_MapT: TypeAlias = dict[int, int] | _EncodingMap +_CharMap: TypeAlias = dict[int, int] | _EncodingMap _Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]] _SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None] @@ -66,11 +66,11 @@ def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) - @overload def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ... def lookup(__encoding: str) -> codecs.CodecInfo: ... -def charmap_build(__map: str) -> _MapT: ... +def charmap_build(__map: str) -> _CharMap: ... def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ... def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ... -def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[str, int]: ... -def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _MapT | None = ...) -> tuple[bytes, int]: ... +def charmap_decode(__data: bytes, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[str, int]: ... +def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[bytes, int]: ... def escape_decode(__data: str | bytes, __errors: str | None = ...) -> tuple[str, int]: ... def escape_encode(__data: bytes, __errors: str | None = ...) -> tuple[bytes, int]: ... def latin_1_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ... diff --git a/mypy/typeshed/stdlib/_curses.pyi b/mypy/typeshed/stdlib/_curses.pyi index 95a128a32256..1d10e93c5f92 100644 --- a/mypy/typeshed/stdlib/_curses.pyi +++ b/mypy/typeshed/stdlib/_curses.pyi @@ -4,7 +4,7 @@ from typing import IO, Any, NamedTuple, overload from typing_extensions import TypeAlias, final if sys.platform != "win32": - _chtype: TypeAlias = str | bytes | int + _ChType: TypeAlias = str | bytes | int # ACS codes are only initialized after initscr is called ACS_BBSS: int @@ -365,9 +365,9 @@ if sys.platform != "win32": __i9: int = ..., ) -> bytes: ... def typeahead(__fd: int) -> None: ... - def unctrl(__ch: _chtype) -> bytes: ... + def unctrl(__ch: _ChType) -> bytes: ... def unget_wch(__ch: int | str) -> None: ... - def ungetch(__ch: _chtype) -> None: ... + def ungetch(__ch: _ChType) -> None: ... def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ... def update_lines_cols() -> None: ... def use_default_colors() -> None: ... @@ -379,9 +379,9 @@ if sys.platform != "win32": class _CursesWindow: encoding: str @overload - def addch(self, ch: _chtype, attr: int = ...) -> None: ... + def addch(self, ch: _ChType, attr: int = ...) -> None: ... @overload - def addch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ... + def addch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ... @overload def addnstr(self, str: str, n: int, attr: int = ...) -> None: ... @overload @@ -393,23 +393,23 @@ if sys.platform != "win32": def attroff(self, __attr: int) -> None: ... def attron(self, __attr: int) -> None: ... def attrset(self, __attr: int) -> None: ... - def bkgd(self, __ch: _chtype, __attr: int = ...) -> None: ... - def bkgdset(self, __ch: _chtype, __attr: int = ...) -> None: ... + def bkgd(self, __ch: _ChType, __attr: int = ...) -> None: ... + def bkgdset(self, __ch: _ChType, __attr: int = ...) -> None: ... def border( self, - ls: _chtype = ..., - rs: _chtype = ..., - ts: _chtype = ..., - bs: _chtype = ..., - tl: _chtype = ..., - tr: _chtype = ..., - bl: _chtype = ..., - br: _chtype = ..., + ls: _ChType = ..., + rs: _ChType = ..., + ts: _ChType = ..., + bs: _ChType = ..., + tl: _ChType = ..., + tr: _ChType = ..., + bl: _ChType = ..., + br: _ChType = ..., ) -> None: ... @overload def box(self) -> None: ... @overload - def box(self, vertch: _chtype = ..., horch: _chtype = ...) -> None: ... + def box(self, vertch: _ChType = ..., horch: _ChType = ...) -> None: ... @overload def chgat(self, attr: int) -> None: ... @overload @@ -432,7 +432,7 @@ if sys.platform != "win32": def derwin(self, begin_y: int, begin_x: int) -> _CursesWindow: ... @overload def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> _CursesWindow: ... - def echochar(self, __ch: _chtype, __attr: int = ...) -> None: ... + def echochar(self, __ch: _ChType, __attr: int = ...) -> None: ... def enclose(self, __y: int, __x: int) -> bool: ... def erase(self) -> None: ... def getbegyx(self) -> tuple[int, int]: ... @@ -461,9 +461,9 @@ if sys.platform != "win32": def getstr(self, y: int, x: int, n: int) -> bytes: ... def getyx(self) -> tuple[int, int]: ... @overload - def hline(self, ch: _chtype, n: int) -> None: ... + def hline(self, ch: _ChType, n: int) -> None: ... @overload - def hline(self, y: int, x: int, ch: _chtype, n: int) -> None: ... + def hline(self, y: int, x: int, ch: _ChType, n: int) -> None: ... def idcok(self, flag: bool) -> None: ... def idlok(self, yes: bool) -> None: ... def immedok(self, flag: bool) -> None: ... @@ -472,9 +472,9 @@ if sys.platform != "win32": @overload def inch(self, y: int, x: int) -> int: ... @overload - def insch(self, ch: _chtype, attr: int = ...) -> None: ... + def insch(self, ch: _ChType, attr: int = ...) -> None: ... @overload - def insch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ... + def insch(self, y: int, x: int, ch: _ChType, attr: int = ...) -> None: ... def insdelln(self, nlines: int) -> None: ... def insertln(self) -> None: ... @overload @@ -543,9 +543,9 @@ if sys.platform != "win32": def touchwin(self) -> None: ... def untouchwin(self) -> None: ... @overload - def vline(self, ch: _chtype, n: int) -> None: ... + def vline(self, ch: _ChType, n: int) -> None: ... @overload - def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ... + def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ... if sys.version_info >= (3, 8): class _ncurses_version(NamedTuple): major: int diff --git a/mypy/typeshed/stdlib/_decimal.pyi b/mypy/typeshed/stdlib/_decimal.pyi index a259058ee163..515ed13d2a63 100644 --- a/mypy/typeshed/stdlib/_decimal.pyi +++ b/mypy/typeshed/stdlib/_decimal.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import Self from collections.abc import Container, Sequence from types import TracebackType -from typing import Any, NamedTuple, Union, overload +from typing import Any, ClassVar, NamedTuple, Union, overload from typing_extensions import TypeAlias _Decimal: TypeAlias = Decimal | int @@ -209,7 +209,8 @@ class Context: def clear_traps(self) -> None: ... def copy(self) -> Context: ... def __copy__(self) -> Context: ... - __hash__: Any + # see https://github.com/python/cpython/issues/94107 + __hash__: ClassVar[None] # type: ignore[assignment] def Etiny(self) -> int: ... def Etop(self) -> int: ... def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ... diff --git a/mypy/typeshed/stdlib/_dummy_threading.pyi b/mypy/typeshed/stdlib/_dummy_threading.pyi index 6f888b3dda70..583127500be8 100644 --- a/mypy/typeshed/stdlib/_dummy_threading.pyi +++ b/mypy/typeshed/stdlib/_dummy_threading.pyi @@ -1,13 +1,9 @@ import sys +from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping -from types import FrameType, TracebackType +from types import TracebackType from typing import Any, TypeVar -from typing_extensions import TypeAlias -# TODO recursive type -_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] - -_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") __all__ = [ @@ -43,8 +39,8 @@ def currentThread() -> Thread: ... def get_ident() -> int: ... def enumerate() -> list[Thread]: ... def main_thread() -> Thread: ... -def settrace(func: _TF) -> None: ... -def setprofile(func: _PF | None) -> None: ... +def settrace(func: TraceFunction) -> None: ... +def setprofile(func: ProfileFunction | None) -> None: ... def stack_size(size: int = ...) -> int: ... TIMEOUT_MAX: float diff --git a/mypy/typeshed/stdlib/_socket.pyi b/mypy/typeshed/stdlib/_socket.pyi index e49cdfbb983a..7af5be43c234 100644 --- a/mypy/typeshed/stdlib/_socket.pyi +++ b/mypy/typeshed/stdlib/_socket.pyi @@ -30,8 +30,6 @@ _RetAddress: TypeAlias = Any has_ipv6: bool -# Per socketmodule.c, only these three families are portable -AF_UNIX: int AF_INET: int AF_INET6: int @@ -46,58 +44,56 @@ if sys.platform == "linux": SOCK_NONBLOCK: int # Address families not mentioned in the docs -AF_AAL5: int AF_APPLETALK: int -AF_ASH: int -AF_ATMPVC: int -AF_ATMSVC: int -AF_AX25: int -AF_BRIDGE: int AF_DECnet: int -AF_ECONET: int AF_IPX: int -AF_IRDA: int -AF_KEY: int -AF_LLC: int -AF_NETBEUI: int -AF_NETROM: int -AF_PPPOX: int -AF_ROSE: int -AF_ROUTE: int -AF_SECURITY: int AF_SNA: int -AF_SYSTEM: int AF_UNSPEC: int -AF_WANPIPE: int -AF_X25: int + +if sys.platform != "win32": + AF_ROUTE: int + AF_SYSTEM: int + AF_UNIX: int + +if sys.platform != "darwin": + AF_IRDA: int + +if sys.platform != "darwin" and sys.platform != "win32": + AF_AAL5: int + AF_ASH: int + AF_ATMPVC: int + AF_ATMSVC: int + AF_AX25: int + AF_BRIDGE: int + AF_ECONET: int + AF_KEY: int + AF_LLC: int + AF_NETBEUI: int + AF_NETROM: int + AF_PPPOX: int + AF_ROSE: int + AF_SECURITY: int + AF_WANPIPE: int + AF_X25: int # The "many constants" referenced by the docs SOMAXCONN: int AI_ADDRCONFIG: int AI_ALL: int AI_CANONNAME: int -AI_DEFAULT: int -AI_MASK: int AI_NUMERICHOST: int AI_NUMERICSERV: int AI_PASSIVE: int AI_V4MAPPED: int -AI_V4MAPPED_CFG: int -EAI_ADDRFAMILY: int EAI_AGAIN: int EAI_BADFLAGS: int -EAI_BADHINTS: int EAI_FAIL: int EAI_FAMILY: int -EAI_MAX: int EAI_MEMORY: int EAI_NODATA: int EAI_NONAME: int -EAI_OVERFLOW: int -EAI_PROTOCOL: int EAI_SERVICE: int EAI_SOCKTYPE: int -EAI_SYSTEM: int INADDR_ALLHOSTS_GROUP: int INADDR_ANY: int INADDR_BROADCAST: int @@ -107,103 +103,82 @@ INADDR_NONE: int INADDR_UNSPEC_GROUP: int IPPORT_RESERVED: int IPPORT_USERRESERVED: int -IPPROTO_AH: int -IPPROTO_BIP: int -IPPROTO_DSTOPTS: int -IPPROTO_EGP: int -IPPROTO_EON: int -IPPROTO_ESP: int -IPPROTO_FRAGMENT: int -IPPROTO_GGP: int -IPPROTO_GRE: int -IPPROTO_HELLO: int -IPPROTO_HOPOPTS: int + +if sys.platform != "win32" or sys.version_info >= (3, 8): + IPPROTO_AH: int + IPPROTO_DSTOPTS: int + IPPROTO_EGP: int + IPPROTO_ESP: int + IPPROTO_FRAGMENT: int + IPPROTO_GGP: int + IPPROTO_HOPOPTS: int + IPPROTO_ICMPV6: int + IPPROTO_IDP: int + IPPROTO_IGMP: int + IPPROTO_IPV4: int + IPPROTO_IPV6: int + IPPROTO_MAX: int + IPPROTO_ND: int + IPPROTO_NONE: int + IPPROTO_PIM: int + IPPROTO_PUP: int + IPPROTO_ROUTING: int + IPPROTO_SCTP: int + + if sys.platform != "darwin": + IPPROTO_CBT: int + IPPROTO_ICLFXBM: int + IPPROTO_IGP: int + IPPROTO_L2TP: int + IPPROTO_PGM: int + IPPROTO_RDP: int + IPPROTO_ST: int + IPPROTO_ICMP: int -IPPROTO_ICMPV6: int -IPPROTO_IDP: int -IPPROTO_IGMP: int IPPROTO_IP: int -IPPROTO_IPCOMP: int -IPPROTO_IPIP: int -IPPROTO_IPV4: int -IPPROTO_IPV6: int -IPPROTO_MAX: int -IPPROTO_MOBILE: int -IPPROTO_ND: int -IPPROTO_NONE: int -IPPROTO_PIM: int -IPPROTO_PUP: int IPPROTO_RAW: int -IPPROTO_ROUTING: int -IPPROTO_RSVP: int -IPPROTO_SCTP: int IPPROTO_TCP: int -IPPROTO_TP: int IPPROTO_UDP: int -IPPROTO_VRRP: int -IPPROTO_XTP: int IPV6_CHECKSUM: int -IPV6_DONTFRAG: int -IPV6_DSTOPTS: int -IPV6_HOPLIMIT: int -IPV6_HOPOPTS: int IPV6_JOIN_GROUP: int IPV6_LEAVE_GROUP: int IPV6_MULTICAST_HOPS: int IPV6_MULTICAST_IF: int IPV6_MULTICAST_LOOP: int -IPV6_NEXTHOP: int -IPV6_PATHMTU: int -IPV6_PKTINFO: int -IPV6_RECVDSTOPTS: int -IPV6_RECVHOPLIMIT: int -IPV6_RECVHOPOPTS: int -IPV6_RECVPATHMTU: int -IPV6_RECVPKTINFO: int -IPV6_RECVRTHDR: int IPV6_RECVTCLASS: int -IPV6_RTHDR: int -IPV6_RTHDRDSTOPTS: int -IPV6_RTHDR_TYPE_0: int IPV6_TCLASS: int IPV6_UNICAST_HOPS: int -IPV6_USE_MIN_MTU: int IPV6_V6ONLY: int -IPX_TYPE: int + +if sys.platform != "darwin" or sys.version_info >= (3, 9): + IPV6_DONTFRAG: int + IPV6_HOPLIMIT: int + IPV6_HOPOPTS: int + IPV6_PKTINFO: int + IPV6_RECVRTHDR: int + IPV6_RTHDR: int + IP_ADD_MEMBERSHIP: int -IP_DEFAULT_MULTICAST_LOOP: int -IP_DEFAULT_MULTICAST_TTL: int IP_DROP_MEMBERSHIP: int IP_HDRINCL: int -IP_MAX_MEMBERSHIPS: int IP_MULTICAST_IF: int IP_MULTICAST_LOOP: int IP_MULTICAST_TTL: int IP_OPTIONS: int IP_RECVDSTADDR: int -IP_RECVOPTS: int -IP_RECVRETOPTS: int -IP_RETOPTS: int +if sys.version_info >= (3, 10): + IP_RECVTOS: int +elif sys.platform != "win32" and sys.platform != "darwin": + IP_RECVTOS: int IP_TOS: int -IP_TRANSPARENT: int IP_TTL: int -LOCAL_PEERCRED: int -MSG_BCAST: int -MSG_BTAG: int -MSG_CMSG_CLOEXEC: int -MSG_CONFIRM: int MSG_CTRUNC: int MSG_DONTROUTE: int -MSG_DONTWAIT: int -MSG_EOF: int -MSG_EOR: int -MSG_ERRQUEUE: int -MSG_ETAG: int -MSG_FASTOPEN: int -MSG_MCAST: int -MSG_MORE: int -MSG_NOSIGNAL: int -MSG_NOTIFICATION: int + +if sys.platform != "darwin": + if sys.platform != "win32" or sys.version_info >= (3, 7): + MSG_ERRQUEUE: int + MSG_OOB: int MSG_PEEK: int MSG_TRUNC: int @@ -215,42 +190,25 @@ NI_NAMEREQD: int NI_NOFQDN: int NI_NUMERICHOST: int NI_NUMERICSERV: int -SCM_CREDENTIALS: int -SCM_CREDS: int -SCM_RIGHTS: int SHUT_RD: int SHUT_RDWR: int SHUT_WR: int -SOL_ATALK: int -SOL_AX25: int -SOL_HCI: int SOL_IP: int -SOL_IPX: int -SOL_NETROM: int -SOL_ROSE: int SOL_SOCKET: int SOL_TCP: int SOL_UDP: int SO_ACCEPTCONN: int -SO_BINDTODEVICE: int SO_BROADCAST: int SO_DEBUG: int SO_DONTROUTE: int SO_ERROR: int -SO_EXCLUSIVEADDRUSE: int SO_KEEPALIVE: int SO_LINGER: int -SO_MARK: int SO_OOBINLINE: int -SO_PASSCRED: int -SO_PEERCRED: int -SO_PRIORITY: int SO_RCVBUF: int SO_RCVLOWAT: int SO_RCVTIMEO: int SO_REUSEADDR: int -SO_REUSEPORT: int -SO_SETFIB: int SO_SNDBUF: int SO_SNDLOWAT: int SO_SNDTIMEO: int @@ -258,24 +216,109 @@ SO_TYPE: int SO_USELOOPBACK: int if sys.platform == "linux" and sys.version_info >= (3, 11): SO_INCOMING_CPU: int -TCP_CORK: int -TCP_DEFER_ACCEPT: int TCP_FASTOPEN: int -TCP_INFO: int TCP_KEEPCNT: int -TCP_KEEPIDLE: int -TCP_KEEPINTVL: int -TCP_LINGER2: int + +if sys.platform != "win32" or sys.version_info >= (3, 7): + TCP_KEEPINTVL: int + if sys.platform != "darwin": + TCP_KEEPIDLE: int + TCP_MAXSEG: int TCP_NODELAY: int -TCP_QUICKACK: int -TCP_SYNCNT: int -TCP_WINDOW_CLAMP: int -if sys.version_info >= (3, 7): +if sys.version_info >= (3, 7) and sys.platform != "win32": TCP_NOTSENT_LOWAT: int +if sys.version_info >= (3, 10) and sys.platform == "darwin": + TCP_KEEPALIVE: int if sys.version_info >= (3, 11) and sys.platform == "darwin": TCP_CONNECTION_INFO: int +if sys.platform != "darwin": + MSG_BCAST: int + MSG_MCAST: int + SO_EXCLUSIVEADDRUSE: int + +if sys.platform != "win32": + AI_DEFAULT: int + AI_MASK: int + AI_V4MAPPED_CFG: int + EAI_ADDRFAMILY: int + EAI_BADHINTS: int + EAI_MAX: int + EAI_OVERFLOW: int + EAI_PROTOCOL: int + EAI_SYSTEM: int + IPPROTO_EON: int + IPPROTO_GRE: int + IPPROTO_HELLO: int + IPPROTO_IPCOMP: int + IPPROTO_IPIP: int + IPPROTO_RSVP: int + IPPROTO_TP: int + IPPROTO_XTP: int + IPV6_RTHDR_TYPE_0: int + IP_DEFAULT_MULTICAST_LOOP: int + IP_DEFAULT_MULTICAST_TTL: int + IP_MAX_MEMBERSHIPS: int + IP_RECVOPTS: int + IP_RECVRETOPTS: int + IP_RETOPTS: int + LOCAL_PEERCRED: int + MSG_DONTWAIT: int + MSG_EOF: int + MSG_EOR: int + MSG_NOSIGNAL: int # Sometimes this exists on darwin, sometimes not + SCM_CREDS: int + SCM_RIGHTS: int + SO_REUSEPORT: int + +if sys.platform != "win32": + if sys.platform != "darwin" or sys.version_info >= (3, 9): + IPV6_DSTOPTS: int + IPV6_NEXTHOP: int + IPV6_PATHMTU: int + IPV6_RECVDSTOPTS: int + IPV6_RECVHOPLIMIT: int + IPV6_RECVHOPOPTS: int + IPV6_RECVPATHMTU: int + IPV6_RECVPKTINFO: int + IPV6_RTHDRDSTOPTS: int + IPV6_USE_MIN_MTU: int + +if sys.platform != "win32" and sys.platform != "darwin": + IPPROTO_BIP: int + IPPROTO_MOBILE: int + IPPROTO_VRRP: int + IPX_TYPE: int + IP_TRANSPARENT: int + MSG_BTAG: int + MSG_CMSG_CLOEXEC: int + MSG_CONFIRM: int + MSG_ETAG: int + MSG_FASTOPEN: int + MSG_MORE: int + MSG_NOTIFICATION: int + SCM_CREDENTIALS: int + SOL_ATALK: int + SOL_AX25: int + SOL_HCI: int + SOL_IPX: int + SOL_NETROM: int + SOL_ROSE: int + SO_BINDTODEVICE: int + SO_MARK: int + SO_PASSCRED: int + SO_PEERCRED: int + SO_PRIORITY: int + SO_SETFIB: int + TCP_CORK: int + TCP_DEFER_ACCEPT: int + TCP_INFO: int + TCP_LINGER2: int + TCP_QUICKACK: int + TCP_SYNCNT: int + TCP_WINDOW_CLAMP: int + # Specifically-documented constants if sys.platform == "linux": @@ -402,7 +445,6 @@ if sys.platform == "win32": SIO_RCVALL: int SIO_KEEPALIVE_VALS: int SIO_LOOPBACK_FAST_PATH: int - RCVALL_IPLEVEL: int RCVALL_MAX: int RCVALL_OFF: int RCVALL_ON: int @@ -460,16 +502,18 @@ if sys.platform == "linux" and sys.version_info >= (3, 7): SO_VM_SOCKETS_BUFFER_MIN_SIZE: int VM_SOCKETS_INVALID_VERSION: int -AF_LINK: int # Availability: BSD, macOS +if sys.platform != "win32" or sys.version_info >= (3, 9): + AF_LINK: int # BDADDR_* and HCI_* listed with other bluetooth constants below -SO_DOMAIN: int -SO_PASSSEC: int -SO_PEERSEC: int -SO_PROTOCOL: int -TCP_CONGESTION: int -TCP_USER_TIMEOUT: int +if sys.platform != "win32" and sys.platform != "darwin": + SO_DOMAIN: int + SO_PASSSEC: int + SO_PEERSEC: int + SO_PROTOCOL: int + TCP_CONGESTION: int + TCP_USER_TIMEOUT: int if sys.platform == "linux" and sys.version_info >= (3, 8): AF_QIPCRTR: int @@ -495,18 +539,19 @@ if sys.platform == "linux": NETLINK_W1: int NETLINK_XFRM: int +if sys.platform != "darwin": + if sys.platform != "win32" or sys.version_info >= (3, 9): + AF_BLUETOOTH: int + BDADDR_ANY: str + BDADDR_LOCAL: str + BTPROTO_RFCOMM: int + if sys.platform != "win32" and sys.platform != "darwin": # Linux and some BSD support is explicit in the docs # Windows and macOS do not support in practice - AF_BLUETOOTH: int BTPROTO_HCI: int BTPROTO_L2CAP: int - BTPROTO_RFCOMM: int BTPROTO_SCO: int # not in FreeBSD - - BDADDR_ANY: str - BDADDR_LOCAL: str - HCI_FILTER: int # not in NetBSD or DragonFlyBSD # not in FreeBSD, NetBSD, or DragonFlyBSD HCI_TIME_STAMP: int @@ -635,14 +680,14 @@ def inet_aton(__ip_string: str) -> bytes: ... # ret val 4 bytes in length def inet_ntoa(__packed_ip: bytes) -> str: ... def inet_pton(__address_family: int, __ip_string: str) -> bytes: ... def inet_ntop(__address_family: int, __packed_ip: bytes) -> str: ... -def CMSG_LEN(__length: int) -> int: ... -def CMSG_SPACE(__length: int) -> int: ... def getdefaulttimeout() -> float | None: ... def setdefaulttimeout(__timeout: float | None) -> None: ... -def socketpair(__family: int = ..., __type: int = ..., __proto: int = ...) -> tuple[socket, socket]: ... if sys.platform != "win32": def sethostname(__name: str) -> None: ... + def CMSG_LEN(__length: int) -> int: ... + def CMSG_SPACE(__length: int) -> int: ... + def socketpair(__family: int = ..., __type: int = ..., __proto: int = ...) -> tuple[socket, socket]: ... # Windows added these in 3.8, but didn't have them before if sys.platform != "win32" or sys.version_info >= (3, 8): diff --git a/mypy/typeshed/stdlib/_thread.pyi b/mypy/typeshed/stdlib/_thread.pyi index c5da8ccf3a90..10a191cbdf78 100644 --- a/mypy/typeshed/stdlib/_thread.pyi +++ b/mypy/typeshed/stdlib/_thread.pyi @@ -9,9 +9,6 @@ from typing_extensions import Final, final error = RuntimeError def _count() -> int: ... - -_dangling: Any - @final class LockType: def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... diff --git a/mypy/typeshed/stdlib/_threading_local.pyi b/mypy/typeshed/stdlib/_threading_local.pyi index def996fba117..17ce1fe349fe 100644 --- a/mypy/typeshed/stdlib/_threading_local.pyi +++ b/mypy/typeshed/stdlib/_threading_local.pyi @@ -3,14 +3,14 @@ from typing_extensions import TypeAlias from weakref import ReferenceType __all__ = ["local"] -_localdict: TypeAlias = dict[Any, Any] +_LocalDict: TypeAlias = dict[Any, Any] class _localimpl: key: str - dicts: dict[int, tuple[ReferenceType[Any], _localdict]] + dicts: dict[int, tuple[ReferenceType[Any], _LocalDict]] def __init__(self) -> None: ... - def get_dict(self) -> _localdict: ... - def create_dict(self) -> _localdict: ... + def get_dict(self) -> _LocalDict: ... + def create_dict(self) -> _LocalDict: ... class local: def __getattribute__(self, name: str) -> Any: ... diff --git a/mypy/typeshed/stdlib/_tracemalloc.pyi b/mypy/typeshed/stdlib/_tracemalloc.pyi index 6e3c4e59a07a..2262d4b16b3a 100644 --- a/mypy/typeshed/stdlib/_tracemalloc.pyi +++ b/mypy/typeshed/stdlib/_tracemalloc.pyi @@ -1,9 +1,9 @@ import sys from collections.abc import Sequence -from tracemalloc import _FrameTupleT, _TraceTupleT +from tracemalloc import _FrameTuple, _TraceTuple -def _get_object_traceback(__obj: object) -> Sequence[_FrameTupleT] | None: ... -def _get_traces() -> Sequence[_TraceTupleT]: ... +def _get_object_traceback(__obj: object) -> Sequence[_FrameTuple] | None: ... +def _get_traces() -> Sequence[_TraceTuple]: ... def clear_traces() -> None: ... def get_traceback_limit() -> int: ... def get_traced_memory() -> tuple[int, int]: ... diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index 005849e0fb05..ad78640b4ecc 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -7,9 +7,9 @@ import ctypes import mmap import pickle import sys -from collections.abc import Awaitable, Container, Iterable, Set as AbstractSet +from collections.abc import Awaitable, Callable, Container, Iterable, Set as AbstractSet from os import PathLike -from types import TracebackType +from types import FrameType, TracebackType from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union from typing_extensions import Final, Literal, LiteralString, TypeAlias, final @@ -50,21 +50,23 @@ class SupportsAnext(Protocol[_T_co]): # Comparison protocols -class SupportsDunderLT(Protocol): - def __lt__(self, __other: Any) -> bool: ... +class SupportsDunderLT(Protocol[_T_contra]): + def __lt__(self, __other: _T_contra) -> bool: ... -class SupportsDunderGT(Protocol): - def __gt__(self, __other: Any) -> bool: ... +class SupportsDunderGT(Protocol[_T_contra]): + def __gt__(self, __other: _T_contra) -> bool: ... -class SupportsDunderLE(Protocol): - def __le__(self, __other: Any) -> bool: ... +class SupportsDunderLE(Protocol[_T_contra]): + def __le__(self, __other: _T_contra) -> bool: ... -class SupportsDunderGE(Protocol): - def __ge__(self, __other: Any) -> bool: ... +class SupportsDunderGE(Protocol[_T_contra]): + def __ge__(self, __other: _T_contra) -> bool: ... -class SupportsAllComparisons(SupportsDunderLT, SupportsDunderGT, SupportsDunderLE, SupportsDunderGE, Protocol): ... +class SupportsAllComparisons( + SupportsDunderLT[Any], SupportsDunderGT[Any], SupportsDunderLE[Any], SupportsDunderGE[Any], Protocol +): ... -SupportsRichComparison: TypeAlias = SupportsDunderLT | SupportsDunderGT +SupportsRichComparison: TypeAlias = SupportsDunderLT[Any] | SupportsDunderGT[Any] SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison) # noqa: Y001 # Dunder protocols @@ -263,3 +265,10 @@ class structseq(Generic[_T_co]): # Superset of typing.AnyStr that also inclues LiteralString AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001 + +# Objects suitable to be passed to sys.setprofile, threading.setprofile, and similar +ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object] + +# Objects suitable to be passed to sys.settrace, threading.settrace, and similar +# TODO: Ideally this would be a recursive type alias +TraceFunction: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] diff --git a/mypy/typeshed/stdlib/_weakref.pyi b/mypy/typeshed/stdlib/_weakref.pyi index 2d3faec1fa68..329cd0dd6458 100644 --- a/mypy/typeshed/stdlib/_weakref.pyi +++ b/mypy/typeshed/stdlib/_weakref.pyi @@ -1,4 +1,5 @@ import sys +from _typeshed import Self from collections.abc import Callable from typing import Any, Generic, TypeVar, overload from typing_extensions import final @@ -20,7 +21,7 @@ class ProxyType(Generic[_T]): # "weakproxy" class ReferenceType(Generic[_T]): __callback__: Callable[[ReferenceType[_T]], Any] - def __init__(self, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> None: ... + def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ... def __call__(self) -> _T | None: ... def __hash__(self) -> int: ... if sys.version_info >= (3, 9): diff --git a/mypy/typeshed/stdlib/abc.pyi b/mypy/typeshed/stdlib/abc.pyi index 58985067b125..f7f82333a362 100644 --- a/mypy/typeshed/stdlib/abc.pyi +++ b/mypy/typeshed/stdlib/abc.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import SupportsWrite +from _typeshed import Self, SupportsWrite from collections.abc import Callable from typing import Any, Generic, TypeVar from typing_extensions import Literal @@ -11,7 +11,16 @@ _FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) # These definitions have special processing in mypy class ABCMeta(type): __abstractmethods__: frozenset[str] - def __init__(self, name: str, bases: tuple[type, ...], namespace: dict[str, Any]) -> None: ... + if sys.version_info >= (3, 11): + def __new__( + __mcls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwargs: Any + ) -> Self: ... + else: + # pyright doesn't like the first parameter being called mcls, hence the `pyright: ignore` + def __new__( + mcls: type[Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any # pyright: ignore + ) -> Self: ... + def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ... def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ... def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = ...) -> None: ... diff --git a/mypy/typeshed/stdlib/asynchat.pyi b/mypy/typeshed/stdlib/asynchat.pyi index e1787ca98b4f..57254eef13fd 100644 --- a/mypy/typeshed/stdlib/asynchat.pyi +++ b/mypy/typeshed/stdlib/asynchat.pyi @@ -9,7 +9,7 @@ class simple_producer: class async_chat(asyncore.dispatcher): ac_in_buffer_size: int ac_out_buffer_size: int - def __init__(self, sock: socket.socket | None = ..., map: asyncore._maptype | None = ...) -> None: ... + def __init__(self, sock: socket.socket | None = ..., map: asyncore._MapType | None = ...) -> None: ... @abstractmethod def collect_incoming_data(self, data: bytes) -> None: ... @abstractmethod diff --git a/mypy/typeshed/stdlib/asyncio/base_events.pyi b/mypy/typeshed/stdlib/asyncio/base_events.pyi index 310a9f585591..e413730bc0be 100644 --- a/mypy/typeshed/stdlib/asyncio/base_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/base_events.pyi @@ -1,7 +1,7 @@ import ssl import sys from _typeshed import FileDescriptorLike, WriteableBuffer -from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle +from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle, _TaskFactory from asyncio.futures import Future from asyncio.protocols import BaseProtocol from asyncio.tasks import Task @@ -107,8 +107,8 @@ class BaseEventLoop(AbstractEventLoop): else: def create_task(self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T]) -> Task[_T]: ... - def set_task_factory(self, factory: Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None) -> None: ... - def get_task_factory(self) -> Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None: ... + def set_task_factory(self, factory: _TaskFactory | None) -> None: ... + def get_task_factory(self) -> _TaskFactory | None: ... # Methods for interacting with threads if sys.version_info >= (3, 7): def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ... diff --git a/mypy/typeshed/stdlib/asyncio/coroutines.pyi b/mypy/typeshed/stdlib/asyncio/coroutines.pyi index 6d4d507c6a4c..5c640af5a1ca 100644 --- a/mypy/typeshed/stdlib/asyncio/coroutines.pyi +++ b/mypy/typeshed/stdlib/asyncio/coroutines.pyi @@ -1,5 +1,4 @@ import sys -import types from collections.abc import Coroutine from typing import Any from typing_extensions import TypeGuard @@ -20,8 +19,5 @@ if sys.version_info < (3, 11): def iscoroutinefunction(func: object) -> bool: ... -if sys.version_info >= (3, 8): - def iscoroutine(obj: object) -> TypeGuard[Coroutine[Any, Any, Any]]: ... - -else: - def iscoroutine(obj: object) -> TypeGuard[types.GeneratorType[Any, Any, Any] | Coroutine[Any, Any, Any]]: ... +# Can actually be a generator-style coroutine on Python 3.7 +def iscoroutine(obj: object) -> TypeGuard[Coroutine[Any, Any, Any]]: ... diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index 8396f0957a1e..fb4dac56f01e 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -4,7 +4,7 @@ from _typeshed import FileDescriptorLike, Self, WriteableBuffer from abc import ABCMeta, abstractmethod from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, TypeVar, overload +from typing import IO, Any, Protocol, TypeVar, overload from typing_extensions import Literal, TypeAlias from .base_events import Server @@ -81,6 +81,11 @@ _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] _SSLContext: TypeAlias = bool | None | ssl.SSLContext +class _TaskFactory(Protocol): + def __call__( + self, __loop: AbstractEventLoop, __factory: Coroutine[Any, Any, _T] | Generator[Any, None, _T] + ) -> Future[_T]: ... + class Handle: _cancelled: bool _args: Sequence[Any] @@ -203,9 +208,9 @@ class AbstractEventLoop: def create_task(self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T]) -> Task[_T]: ... @abstractmethod - def set_task_factory(self, factory: Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None) -> None: ... + def set_task_factory(self, factory: _TaskFactory | None) -> None: ... @abstractmethod - def get_task_factory(self) -> Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]] | None: ... + def get_task_factory(self) -> _TaskFactory | None: ... # Methods for interacting with threads if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2 @abstractmethod diff --git a/mypy/typeshed/stdlib/asyncio/sslproto.pyi b/mypy/typeshed/stdlib/asyncio/sslproto.pyi index 77807743f749..1d3d6d7c83ec 100644 --- a/mypy/typeshed/stdlib/asyncio/sslproto.pyi +++ b/mypy/typeshed/stdlib/asyncio/sslproto.pyi @@ -33,34 +33,35 @@ else: _WRAPPED: Literal["WRAPPED"] _SHUTDOWN: Literal["SHUTDOWN"] -class _SSLPipe: +if sys.version_info < (3, 11): + class _SSLPipe: - max_size: ClassVar[int] + max_size: ClassVar[int] - _context: ssl.SSLContext - _server_side: bool - _server_hostname: str | None - _state: str - _incoming: ssl.MemoryBIO - _outgoing: ssl.MemoryBIO - _sslobj: ssl.SSLObject | None - _need_ssldata: bool - _handshake_cb: Callable[[BaseException | None], None] | None - _shutdown_cb: Callable[[], None] | None - def __init__(self, context: ssl.SSLContext, server_side: bool, server_hostname: str | None = ...) -> None: ... - @property - def context(self) -> ssl.SSLContext: ... - @property - def ssl_object(self) -> ssl.SSLObject | None: ... - @property - def need_ssldata(self) -> bool: ... - @property - def wrapped(self) -> bool: ... - def do_handshake(self, callback: Callable[[BaseException | None], None] | None = ...) -> list[bytes]: ... - def shutdown(self, callback: Callable[[], None] | None = ...) -> list[bytes]: ... - def feed_eof(self) -> None: ... - def feed_ssldata(self, data: bytes, only_handshake: bool = ...) -> tuple[list[bytes], list[bytes]]: ... - def feed_appdata(self, data: bytes, offset: int = ...) -> tuple[list[bytes], int]: ... + _context: ssl.SSLContext + _server_side: bool + _server_hostname: str | None + _state: str + _incoming: ssl.MemoryBIO + _outgoing: ssl.MemoryBIO + _sslobj: ssl.SSLObject | None + _need_ssldata: bool + _handshake_cb: Callable[[BaseException | None], None] | None + _shutdown_cb: Callable[[], None] | None + def __init__(self, context: ssl.SSLContext, server_side: bool, server_hostname: str | None = ...) -> None: ... + @property + def context(self) -> ssl.SSLContext: ... + @property + def ssl_object(self) -> ssl.SSLObject | None: ... + @property + def need_ssldata(self) -> bool: ... + @property + def wrapped(self) -> bool: ... + def do_handshake(self, callback: Callable[[BaseException | None], None] | None = ...) -> list[bytes]: ... + def shutdown(self, callback: Callable[[], None] | None = ...) -> list[bytes]: ... + def feed_eof(self) -> None: ... + def feed_ssldata(self, data: bytes, only_handshake: bool = ...) -> tuple[list[bytes], list[bytes]]: ... + def feed_appdata(self, data: bytes, offset: int = ...) -> tuple[list[bytes], int]: ... class _SSLProtocolTransport(transports._FlowControlMixin, transports.Transport): @@ -101,9 +102,6 @@ else: _SSLProtocolBase: TypeAlias = protocols.Protocol class SSLProtocol(_SSLProtocolBase): - if sys.version_info >= (3, 11): - max_size: ClassVar[int] - _server_side: bool _server_hostname: str | None _sslcontext: ssl.SSLContext @@ -113,16 +111,20 @@ class SSLProtocol(_SSLProtocolBase): _waiter: futures.Future[Any] _loop: events.AbstractEventLoop _app_transport: _SSLProtocolTransport - _sslpipe: _SSLPipe | None - _session_established: bool - _in_handshake: bool - _in_shutdown: bool _transport: transports.BaseTransport | None - _call_connection_made: bool _ssl_handshake_timeout: int | None _app_protocol: protocols.BaseProtocol _app_protocol_is_buffer: bool + if sys.version_info >= (3, 11): + max_size: ClassVar[int] + else: + _sslpipe: _SSLPipe | None + _session_established: bool + _call_connection_made: bool + _in_handshake: bool + _in_shutdown: bool + if sys.version_info >= (3, 11): def __init__( self, diff --git a/mypy/typeshed/stdlib/asyncio/tasks.pyi b/mypy/typeshed/stdlib/asyncio/tasks.pyi index d7119b0400ba..8442090f11ea 100644 --- a/mypy/typeshed/stdlib/asyncio/tasks.pyi +++ b/mypy/typeshed/stdlib/asyncio/tasks.pyi @@ -58,7 +58,7 @@ _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _FT = TypeVar("_FT", bound=Future[Any]) -_FutureT: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] +_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T] _TaskYieldType: TypeAlias = Future[object] | None FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED @@ -66,11 +66,11 @@ FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION ALL_COMPLETED = concurrent.futures.ALL_COMPLETED if sys.version_info >= (3, 10): - def as_completed(fs: Iterable[_FutureT[_T]], *, timeout: float | None = ...) -> Iterator[Future[_T]]: ... + def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = ...) -> Iterator[Future[_T]]: ... else: def as_completed( - fs: Iterable[_FutureT[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ... + fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ... ) -> Iterator[Future[_T]]: ... @overload @@ -87,189 +87,193 @@ def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | No # typing PR #1550 for discussion. if sys.version_info >= (3, 10): @overload - def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... + def gather(*, return_exceptions: bool = ...) -> Future[tuple[()]]: ... + @overload + def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], __coro_or_future2: _FutureT[_T2], *, return_exceptions: Literal[False] = ... + __coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: Literal[False] = ... ) -> Future[tuple[_T1, _T2]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload - def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], - return_exceptions: bool = ..., - ) -> Future[list[Any]]: ... - @overload - def gather(__coro_or_future1: _FutureT[_T1], *, return_exceptions: bool = ...) -> Future[tuple[_T1 | BaseException]]: ... + def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], __coro_or_future2: _FutureT[_T2], *, return_exceptions: bool = ... + __coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: bool ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[ tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException] ]: ... + @overload + def gather( + __coro_or_future1: _FutureLike[Any], + __coro_or_future2: _FutureLike[Any], + __coro_or_future3: _FutureLike[Any], + __coro_or_future4: _FutureLike[Any], + __coro_or_future5: _FutureLike[Any], + __coro_or_future6: _FutureLike[Any], + *coros_or_futures: _FutureLike[Any], + return_exceptions: bool = ..., + ) -> Future[list[Any]]: ... else: + @overload + def gather(*, loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...) -> Future[tuple[()]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ... + __coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ... ) -> Future[tuple[_T1]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ..., ) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ... @overload def gather( - __coro_or_future1: _FutureT[Any], - __coro_or_future2: _FutureT[Any], - __coro_or_future3: _FutureT[Any], - __coro_or_future4: _FutureT[Any], - __coro_or_future5: _FutureT[Any], - __coro_or_future6: _FutureT[Any], - *coros_or_futures: _FutureT[Any], - loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., - ) -> Future[list[Any]]: ... - @overload - def gather( - __coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool = ... + __coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool ) -> Future[tuple[_T1 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], *, loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], *, loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], *, loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ... @overload def gather( - __coro_or_future1: _FutureT[_T1], - __coro_or_future2: _FutureT[_T2], - __coro_or_future3: _FutureT[_T3], - __coro_or_future4: _FutureT[_T4], - __coro_or_future5: _FutureT[_T5], + __coro_or_future1: _FutureLike[_T1], + __coro_or_future2: _FutureLike[_T2], + __coro_or_future3: _FutureLike[_T3], + __coro_or_future4: _FutureLike[_T4], + __coro_or_future5: _FutureLike[_T5], *, loop: AbstractEventLoop | None = ..., - return_exceptions: bool = ..., + return_exceptions: bool, ) -> Future[ tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException] ]: ... + @overload + def gather( + __coro_or_future1: _FutureLike[Any], + __coro_or_future2: _FutureLike[Any], + __coro_or_future3: _FutureLike[Any], + __coro_or_future4: _FutureLike[Any], + __coro_or_future5: _FutureLike[Any], + __coro_or_future6: _FutureLike[Any], + *coros_or_futures: _FutureLike[Any], + loop: AbstractEventLoop | None = ..., + return_exceptions: bool = ..., + ) -> Future[list[Any]]: ... -def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... +def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... if sys.version_info >= (3, 10): - def shield(arg: _FutureT[_T]) -> Future[_T]: ... + def shield(arg: _FutureLike[_T]) -> Future[_T]: ... @overload async def sleep(delay: float) -> None: ... @overload @@ -280,10 +284,10 @@ if sys.version_info >= (3, 10): async def wait( fs: Iterable[Awaitable[_T]], *, timeout: float | None = ..., return_when: str = ... ) -> tuple[set[Task[_T]], set[Task[_T]]]: ... - async def wait_for(fut: _FutureT[_T], timeout: float | None) -> _T: ... + async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ... else: - def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ... + def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ... @overload async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ... @overload @@ -296,7 +300,7 @@ else: async def wait( fs: Iterable[Awaitable[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ... ) -> tuple[set[Task[_T]], set[Task[_T]]]: ... - async def wait_for(fut: _FutureT[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ... + async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> _T: ... class Task(Future[_T], Generic[_T]): if sys.version_info >= (3, 8): diff --git a/mypy/typeshed/stdlib/asyncio/windows_utils.pyi b/mypy/typeshed/stdlib/asyncio/windows_utils.pyi index 0a79635b3d4e..db34356cd16d 100644 --- a/mypy/typeshed/stdlib/asyncio/windows_utils.pyi +++ b/mypy/typeshed/stdlib/asyncio/windows_utils.pyi @@ -36,7 +36,7 @@ if sys.platform == "win32": @property def handle(self) -> int: ... def fileno(self) -> int: ... - def close(self, *, CloseHandle: Callable[[int], None] = ...) -> None: ... + def close(self, *, CloseHandle: Callable[[int], object] = ...) -> None: ... class Popen(subprocess.Popen[AnyStr]): stdin: PipeHandle | None # type: ignore[assignment] diff --git a/mypy/typeshed/stdlib/asyncore.pyi b/mypy/typeshed/stdlib/asyncore.pyi index a4a774282343..8c3e03bc3eff 100644 --- a/mypy/typeshed/stdlib/asyncore.pyi +++ b/mypy/typeshed/stdlib/asyncore.pyi @@ -5,22 +5,22 @@ from typing import Any, overload from typing_extensions import TypeAlias # cyclic dependence with asynchat -_maptype: TypeAlias = dict[int, Any] -_socket: TypeAlias = socket +_MapType: TypeAlias = dict[int, Any] +_Socket: TypeAlias = socket -socket_map: _maptype # undocumented +socket_map: _MapType # undocumented class ExitNow(Exception): ... def read(obj: Any) -> None: ... def write(obj: Any) -> None: ... def readwrite(obj: Any, flags: int) -> None: ... -def poll(timeout: float = ..., map: _maptype | None = ...) -> None: ... -def poll2(timeout: float = ..., map: _maptype | None = ...) -> None: ... +def poll(timeout: float = ..., map: _MapType | None = ...) -> None: ... +def poll2(timeout: float = ..., map: _MapType | None = ...) -> None: ... poll3 = poll2 -def loop(timeout: float = ..., use_poll: bool = ..., map: _maptype | None = ..., count: int | None = ...) -> None: ... +def loop(timeout: float = ..., use_poll: bool = ..., map: _MapType | None = ..., count: int | None = ...) -> None: ... # Not really subclass of socket.socket; it's only delegation. # It is not covariant to it. @@ -32,19 +32,19 @@ class dispatcher: connecting: bool closing: bool ignore_log_types: frozenset[str] - socket: _socket | None - def __init__(self, sock: _socket | None = ..., map: _maptype | None = ...) -> None: ... - def add_channel(self, map: _maptype | None = ...) -> None: ... - def del_channel(self, map: _maptype | None = ...) -> None: ... + socket: _Socket | None + def __init__(self, sock: _Socket | None = ..., map: _MapType | None = ...) -> None: ... + def add_channel(self, map: _MapType | None = ...) -> None: ... + def del_channel(self, map: _MapType | None = ...) -> None: ... def create_socket(self, family: int = ..., type: int = ...) -> None: ... - def set_socket(self, sock: _socket, map: _maptype | None = ...) -> None: ... + def set_socket(self, sock: _Socket, map: _MapType | None = ...) -> None: ... def set_reuse_addr(self) -> None: ... def readable(self) -> bool: ... def writable(self) -> bool: ... def listen(self, num: int) -> None: ... def bind(self, addr: tuple[Any, ...] | str) -> None: ... def connect(self, address: tuple[Any, ...] | str) -> None: ... - def accept(self) -> tuple[_socket, Any] | None: ... + def accept(self) -> tuple[_Socket, Any] | None: ... def send(self, data: bytes) -> int: ... def recv(self, buffer_size: int) -> bytes: ... def close(self) -> None: ... @@ -63,14 +63,14 @@ class dispatcher: def handle_close(self) -> None: ... class dispatcher_with_send(dispatcher): - def __init__(self, sock: socket | None = ..., map: _maptype | None = ...) -> None: ... + def __init__(self, sock: socket | None = ..., map: _MapType | None = ...) -> None: ... def initiate_send(self) -> None: ... def handle_write(self) -> None: ... # incompatible signature: # def send(self, data: bytes) -> int | None: ... def compact_traceback() -> tuple[tuple[str, str, str], type, type, str]: ... -def close_all(map: _maptype | None = ..., ignore_all: bool = ...) -> None: ... +def close_all(map: _MapType | None = ..., ignore_all: bool = ...) -> None: ... if sys.platform != "win32": class file_wrapper: @@ -88,5 +88,5 @@ if sys.platform != "win32": def fileno(self) -> int: ... class file_dispatcher(dispatcher): - def __init__(self, fd: FileDescriptorLike, map: _maptype | None = ...) -> None: ... + def __init__(self, fd: FileDescriptorLike, map: _MapType | None = ...) -> None: ... def set_file(self, fd: int) -> None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 9d1d1f4b1b10..381d3358b7ec 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -192,6 +192,7 @@ class super: _PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] _NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20] +_LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed class int: @overload @@ -817,7 +818,12 @@ class slice: def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): - def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ... + # overloads are ordered this way to pass `isinstance` checks + # see: https://github.com/python/typeshed/pull/7454#issuecomment-1061490888 + @overload + def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ... + @overload + def __new__(cls) -> tuple[()]: ... def __len__(self) -> int: ... def __contains__(self, __x: object) -> bool: ... @overload @@ -1556,14 +1562,14 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # In general, the return type of `x + x` is *not* guaranteed to be the same type as x. # However, we can't express that in the stub for `sum()` # without creating many false-positive errors (see #7578). -# Instead, we special-case the most common example of this: bool. +# Instead, we special-case the most common examples of this: bool and literal integers. if sys.version_info >= (3, 8): @overload - def sum(__iterable: Iterable[bool], start: int = ...) -> int: ... # type: ignore[misc] + def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = ...) -> int: ... # type: ignore[misc] else: @overload - def sum(__iterable: Iterable[bool], __start: int = ...) -> int: ... # type: ignore[misc] + def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = ...) -> int: ... # type: ignore[misc] @overload def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ... diff --git a/mypy/typeshed/stdlib/concurrent/futures/process.pyi b/mypy/typeshed/stdlib/concurrent/futures/process.pyi index 1dd2ee0a6105..0c3bea26c31f 100644 --- a/mypy/typeshed/stdlib/concurrent/futures/process.pyi +++ b/mypy/typeshed/stdlib/concurrent/futures/process.pyi @@ -111,7 +111,7 @@ if sys.version_info >= (3, 11): def _process_worker( call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem], - initializer: Callable[..., None] | None, + initializer: Callable[..., object] | None, initargs: tuple[Any, ...], max_tasks: int | None = ..., ) -> None: ... @@ -120,7 +120,7 @@ elif sys.version_info >= (3, 7): def _process_worker( call_queue: Queue[_CallItem], result_queue: SimpleQueue[_ResultItem], - initializer: Callable[..., None] | None, + initializer: Callable[..., object] | None, initargs: tuple[Any, ...], ) -> None: ... @@ -184,7 +184,7 @@ class ProcessPoolExecutor(Executor): self, max_workers: int | None = ..., mp_context: BaseContext | None = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., *, max_tasks_per_child: int | None = ..., @@ -194,7 +194,7 @@ class ProcessPoolExecutor(Executor): self, max_workers: int | None = ..., mp_context: BaseContext | None = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., ) -> None: ... else: diff --git a/mypy/typeshed/stdlib/concurrent/futures/thread.pyi b/mypy/typeshed/stdlib/concurrent/futures/thread.pyi index e10254531788..3579c17dbc6c 100644 --- a/mypy/typeshed/stdlib/concurrent/futures/thread.pyi +++ b/mypy/typeshed/stdlib/concurrent/futures/thread.pyi @@ -32,7 +32,7 @@ if sys.version_info >= (3, 7): def _worker( executor_reference: ref[Any], work_queue: queue.SimpleQueue[Any], - initializer: Callable[..., None], + initializer: Callable[..., object], initargs: tuple[Any, ...], ) -> None: ... @@ -63,7 +63,7 @@ class ThreadPoolExecutor(Executor): self, max_workers: int | None = ..., thread_name_prefix: str = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: tuple[Any, ...] = ..., ) -> None: ... else: diff --git a/mypy/typeshed/stdlib/configparser.pyi b/mypy/typeshed/stdlib/configparser.pyi index 5ffac353ab31..96145f48cd4b 100644 --- a/mypy/typeshed/stdlib/configparser.pyi +++ b/mypy/typeshed/stdlib/configparser.pyi @@ -28,11 +28,10 @@ __all__ = [ "MAX_INTERPOLATION_DEPTH", ] -# Internal type aliases -_section: TypeAlias = Mapping[str, str] -_parser: TypeAlias = MutableMapping[str, _section] -_converter: TypeAlias = Callable[[str], Any] -_converters: TypeAlias = dict[str, _converter] +_Section: TypeAlias = Mapping[str, str] +_Parser: TypeAlias = MutableMapping[str, _Section] +_ConverterCallback: TypeAlias = Callable[[str], Any] +_ConvertersMap: TypeAlias = dict[str, _ConverterCallback] _T = TypeVar("_T") if sys.version_info >= (3, 7): @@ -44,18 +43,18 @@ DEFAULTSECT: Literal["DEFAULT"] MAX_INTERPOLATION_DEPTH: Literal[10] class Interpolation: - def before_get(self, parser: _parser, section: str, option: str, value: str, defaults: _section) -> str: ... - def before_set(self, parser: _parser, section: str, option: str, value: str) -> str: ... - def before_read(self, parser: _parser, section: str, option: str, value: str) -> str: ... - def before_write(self, parser: _parser, section: str, option: str, value: str) -> str: ... + def before_get(self, parser: _Parser, section: str, option: str, value: str, defaults: _Section) -> str: ... + def before_set(self, parser: _Parser, section: str, option: str, value: str) -> str: ... + def before_read(self, parser: _Parser, section: str, option: str, value: str) -> str: ... + def before_write(self, parser: _Parser, section: str, option: str, value: str) -> str: ... class BasicInterpolation(Interpolation): ... class ExtendedInterpolation(Interpolation): ... class LegacyInterpolation(Interpolation): - def before_get(self, parser: _parser, section: str, option: str, value: str, vars: _section) -> str: ... + def before_get(self, parser: _Parser, section: str, option: str, value: str, vars: _Section) -> str: ... -class RawConfigParser(_parser): +class RawConfigParser(_Parser): _SECT_TMPL: ClassVar[str] # undocumented _OPT_TMPL: ClassVar[str] # undocumented _OPT_NV_TMPL: ClassVar[str] # undocumented @@ -81,12 +80,12 @@ class RawConfigParser(_parser): empty_lines_in_values: bool = ..., default_section: str = ..., interpolation: Interpolation | None = ..., - converters: _converters = ..., + converters: _ConvertersMap = ..., ) -> None: ... @overload def __init__( self, - defaults: _section | None = ..., + defaults: _Section | None = ..., dict_type: type[Mapping[str, str]] = ..., allow_no_value: bool = ..., *, @@ -97,15 +96,15 @@ class RawConfigParser(_parser): empty_lines_in_values: bool = ..., default_section: str = ..., interpolation: Interpolation | None = ..., - converters: _converters = ..., + converters: _ConvertersMap = ..., ) -> None: ... def __len__(self) -> int: ... def __getitem__(self, key: str) -> SectionProxy: ... - def __setitem__(self, key: str, value: _section) -> None: ... + def __setitem__(self, key: str, value: _Section) -> None: ... def __delitem__(self, key: str) -> None: ... def __iter__(self) -> Iterator[str]: ... def __contains__(self, key: object) -> bool: ... - def defaults(self) -> _section: ... + def defaults(self) -> _Section: ... def sections(self) -> list[str]: ... def add_section(self, section: str) -> None: ... def has_section(self, section: str) -> bool: ... @@ -119,22 +118,22 @@ class RawConfigParser(_parser): # These get* methods are partially applied (with the same names) in # SectionProxy; the stubs should be kept updated together @overload - def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ... + def getint(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ... @overload def getint( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> int | _T: ... @overload - def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ... + def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ... @overload def getfloat( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> float | _T: ... @overload - def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ... + def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ... @overload def getboolean( - self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T = ... + self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T = ... ) -> bool | _T: ... def _get_conv( self, @@ -143,18 +142,18 @@ class RawConfigParser(_parser): conv: Callable[[str], _T], *, raw: bool = ..., - vars: _section | None = ..., + vars: _Section | None = ..., fallback: _T = ..., ) -> _T: ... # This is incompatible with MutableMapping so we ignore the type @overload # type: ignore[override] - def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ...) -> str: ... + def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> str: ... @overload - def get(self, section: str, option: str, *, raw: bool = ..., vars: _section | None = ..., fallback: _T) -> str | _T: ... + def get(self, section: str, option: str, *, raw: bool = ..., vars: _Section | None = ..., fallback: _T) -> str | _T: ... @overload - def items(self, *, raw: bool = ..., vars: _section | None = ...) -> ItemsView[str, SectionProxy]: ... + def items(self, *, raw: bool = ..., vars: _Section | None = ...) -> ItemsView[str, SectionProxy]: ... @overload - def items(self, section: str, raw: bool = ..., vars: _section | None = ...) -> list[tuple[str, str]]: ... + def items(self, section: str, raw: bool = ..., vars: _Section | None = ...) -> list[tuple[str, str]]: ... def set(self, section: str, option: str, value: str | None = ...) -> None: ... def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = ...) -> None: ... def remove_option(self, section: str, option: str) -> bool: ... @@ -184,32 +183,32 @@ class SectionProxy(MutableMapping[str, str]): fallback: str | None = ..., *, raw: bool = ..., - vars: _section | None = ..., + vars: _Section | None = ..., _impl: Any | None = ..., **kwargs: Any, ) -> str: ... # These are partially-applied version of the methods with the same names in # RawConfigParser; the stubs should be kept updated together @overload - def getint(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> int: ... + def getint(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> int: ... @overload - def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> int | _T: ... + def getint(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> int | _T: ... @overload - def getfloat(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> float: ... + def getfloat(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> float: ... @overload - def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> float | _T: ... + def getfloat(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> float | _T: ... @overload - def getboolean(self, option: str, *, raw: bool = ..., vars: _section | None = ...) -> bool: ... + def getboolean(self, option: str, *, raw: bool = ..., vars: _Section | None = ...) -> bool: ... @overload - def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _section | None = ...) -> bool | _T: ... + def getboolean(self, option: str, fallback: _T = ..., *, raw: bool = ..., vars: _Section | None = ...) -> bool | _T: ... # SectionProxy can have arbitrary attributes when custom converters are used def __getattr__(self, key: str) -> Callable[..., Any]: ... -class ConverterMapping(MutableMapping[str, _converter | None]): - GETTERCRE: Pattern[Any] +class ConverterMapping(MutableMapping[str, _ConverterCallback | None]): + GETTERCRE: ClassVar[Pattern[Any]] def __init__(self, parser: RawConfigParser) -> None: ... - def __getitem__(self, key: str) -> _converter: ... - def __setitem__(self, key: str, value: _converter | None) -> None: ... + def __getitem__(self, key: str) -> _ConverterCallback: ... + def __setitem__(self, key: str, value: _ConverterCallback | None) -> None: ... def __delitem__(self, key: str) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... diff --git a/mypy/typeshed/stdlib/ctypes/__init__.pyi b/mypy/typeshed/stdlib/ctypes/__init__.pyi index ee26cbddefe4..00b2be01dc86 100644 --- a/mypy/typeshed/stdlib/ctypes/__init__.pyi +++ b/mypy/typeshed/stdlib/ctypes/__init__.pyi @@ -190,7 +190,9 @@ def wstring_at(address: _CVoidConstPLike, size: int = ...) -> str: ... class _SimpleCData(Generic[_T], _CData): value: _T - def __init__(self, value: _T = ...) -> None: ... + # The TypeVar can be unsolved here, + # but we can't use overloads without creating many, many mypy false-positive errors + def __init__(self, value: _T = ...) -> None: ... # type: ignore class c_byte(_SimpleCData[int]): ... diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi index e2a359d0a536..bcd3413ac38b 100644 --- a/mypy/typeshed/stdlib/datetime.pyi +++ b/mypy/typeshed/stdlib/datetime.pyi @@ -21,7 +21,7 @@ class tzinfo: def fromutc(self, __dt: datetime) -> datetime: ... # Alias required to avoid name conflicts with date(time).tzinfo. -_tzinfo: TypeAlias = tzinfo +_TzInfo: TypeAlias = tzinfo @final class timezone(tzinfo): @@ -113,7 +113,7 @@ class time: minute: int = ..., second: int = ..., microsecond: int = ..., - tzinfo: _tzinfo | None = ..., + tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... @@ -126,7 +126,7 @@ class time: @property def microsecond(self) -> int: ... @property - def tzinfo(self) -> _tzinfo | None: ... + def tzinfo(self) -> _TzInfo | None: ... @property def fold(self) -> int: ... def __le__(self, __other: time) -> bool: ... @@ -150,13 +150,13 @@ class time: minute: int = ..., second: int = ..., microsecond: int = ..., - tzinfo: _tzinfo | None = ..., + tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... -_date: TypeAlias = date -_time: TypeAlias = time +_Date: TypeAlias = date +_Time: TypeAlias = time class timedelta(SupportsAbs[timedelta]): min: ClassVar[timedelta] @@ -218,7 +218,7 @@ class datetime(date): minute: int = ..., second: int = ..., microsecond: int = ..., - tzinfo: _tzinfo | None = ..., + tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... @@ -231,40 +231,40 @@ class datetime(date): @property def microsecond(self) -> int: ... @property - def tzinfo(self) -> _tzinfo | None: ... + def tzinfo(self) -> _TzInfo | None: ... @property def fold(self) -> int: ... # The first parameter in `fromtimestamp` is actually positional-or-keyword, # but it is named "timestamp" in the C implementation and "t" in the Python implementation, # so it is only truly *safe* to pass it as a positional argument. @classmethod - def fromtimestamp(cls: type[Self], __timestamp: float, tz: _tzinfo | None = ...) -> Self: ... + def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... @classmethod def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ... if sys.version_info >= (3, 8): @classmethod - def now(cls: type[Self], tz: _tzinfo | None = ...) -> Self: ... + def now(cls: type[Self], tz: _TzInfo | None = ...) -> Self: ... else: @overload @classmethod def now(cls: type[Self], tz: None = ...) -> Self: ... @overload @classmethod - def now(cls, tz: _tzinfo) -> datetime: ... + def now(cls, tz: _TzInfo) -> datetime: ... @classmethod def utcnow(cls: type[Self]) -> Self: ... @classmethod - def combine(cls, date: _date, time: _time, tzinfo: _tzinfo | None = ...) -> datetime: ... + def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> datetime: ... if sys.version_info >= (3, 7): @classmethod def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... def timestamp(self) -> float: ... def utctimetuple(self) -> struct_time: ... - def date(self) -> _date: ... - def time(self) -> _time: ... - def timetz(self) -> _time: ... + def date(self) -> _Date: ... + def time(self) -> _Time: ... + def timetz(self) -> _Time: ... def replace( self: Self, year: int = ..., @@ -274,14 +274,14 @@ class datetime(date): minute: int = ..., second: int = ..., microsecond: int = ..., - tzinfo: _tzinfo | None = ..., + tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... if sys.version_info >= (3, 8): - def astimezone(self: Self, tz: _tzinfo | None = ...) -> Self: ... + def astimezone(self: Self, tz: _TzInfo | None = ...) -> Self: ... else: - def astimezone(self, tz: _tzinfo | None = ...) -> datetime: ... + def astimezone(self, tz: _TzInfo | None = ...) -> datetime: ... def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... diff --git a/mypy/typeshed/stdlib/distutils/ccompiler.pyi b/mypy/typeshed/stdlib/distutils/ccompiler.pyi index ed823f7c070f..5b92c5f5c42e 100644 --- a/mypy/typeshed/stdlib/distutils/ccompiler.pyi +++ b/mypy/typeshed/stdlib/distutils/ccompiler.pyi @@ -143,7 +143,7 @@ class CCompiler: def library_filename(self, libname: str, lib_type: str = ..., strip_dir: int = ..., output_dir: str = ...) -> str: ... def object_filenames(self, source_filenames: list[str], strip_dir: int = ..., output_dir: str = ...) -> list[str]: ... def shared_object_filename(self, basename: str, strip_dir: int = ..., output_dir: str = ...) -> str: ... - def execute(self, func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ... + def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., level: int = ...) -> None: ... def spawn(self, cmd: list[str]) -> None: ... def mkpath(self, name: str, mode: int = ...) -> None: ... def move_file(self, src: str, dst: str) -> str: ... diff --git a/mypy/typeshed/stdlib/distutils/util.pyi b/mypy/typeshed/stdlib/distutils/util.pyi index 22d982e6949d..da8d66063536 100644 --- a/mypy/typeshed/stdlib/distutils/util.pyi +++ b/mypy/typeshed/stdlib/distutils/util.pyi @@ -10,7 +10,7 @@ def check_environ() -> None: ... def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ... def split_quoted(s: str) -> list[str]: ... def execute( - func: Callable[..., None], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ... + func: Callable[..., object], args: tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ... ) -> None: ... def strtobool(val: str) -> Literal[0, 1]: ... def byte_compile( diff --git a/mypy/typeshed/stdlib/email/mime/application.pyi b/mypy/typeshed/stdlib/email/mime/application.pyi index 4966a17d9471..dfff85265ade 100644 --- a/mypy/typeshed/stdlib/email/mime/application.pyi +++ b/mypy/typeshed/stdlib/email/mime/application.pyi @@ -10,7 +10,7 @@ class MIMEApplication(MIMENonMultipart): self, _data: str | bytes, _subtype: str = ..., - _encoder: Callable[[MIMEApplication], None] = ..., + _encoder: Callable[[MIMEApplication], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/mypy/typeshed/stdlib/email/mime/audio.pyi b/mypy/typeshed/stdlib/email/mime/audio.pyi index fd107d7fcbc6..b355d55070ad 100644 --- a/mypy/typeshed/stdlib/email/mime/audio.pyi +++ b/mypy/typeshed/stdlib/email/mime/audio.pyi @@ -10,7 +10,7 @@ class MIMEAudio(MIMENonMultipart): self, _audiodata: str | bytes, _subtype: str | None = ..., - _encoder: Callable[[MIMEAudio], None] = ..., + _encoder: Callable[[MIMEAudio], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/mypy/typeshed/stdlib/email/mime/image.pyi b/mypy/typeshed/stdlib/email/mime/image.pyi index 480f6dcab34b..f575103de2d6 100644 --- a/mypy/typeshed/stdlib/email/mime/image.pyi +++ b/mypy/typeshed/stdlib/email/mime/image.pyi @@ -10,7 +10,7 @@ class MIMEImage(MIMENonMultipart): self, _imagedata: str | bytes, _subtype: str | None = ..., - _encoder: Callable[[MIMEImage], None] = ..., + _encoder: Callable[[MIMEImage], object] = ..., *, policy: Policy | None = ..., **_params: _ParamsType, diff --git a/mypy/typeshed/stdlib/errno.pyi b/mypy/typeshed/stdlib/errno.pyi index 9ef1fe6e7618..28874d44ff5f 100644 --- a/mypy/typeshed/stdlib/errno.pyi +++ b/mypy/typeshed/stdlib/errno.pyi @@ -1,3 +1,4 @@ +import sys from collections.abc import Mapping errorcode: Mapping[int, str] @@ -16,7 +17,6 @@ EAGAIN: int ENOMEM: int EACCES: int EFAULT: int -ENOTBLK: int EBUSY: int EEXIST: int EXDEV: int @@ -45,49 +45,16 @@ ELOOP: int EWOULDBLOCK: int ENOMSG: int EIDRM: int -ECHRNG: int -EL2NSYNC: int -EL3HLT: int -EL3RST: int -ELNRNG: int -EUNATCH: int -ENOCSI: int -EL2HLT: int -EBADE: int -EBADR: int -EXFULL: int -ENOANO: int -EBADRQC: int -EBADSLT: int -EDEADLOCK: int -EBFONT: int ENOSTR: int ENODATA: int ETIME: int ENOSR: int -ENONET: int -ENOPKG: int EREMOTE: int ENOLINK: int -EADV: int -ESRMNT: int -ECOMM: int EPROTO: int -EMULTIHOP: int -EDOTDOT: int EBADMSG: int EOVERFLOW: int -ENOTUNIQ: int -EBADFD: int -EREMCHG: int -ELIBACC: int -ELIBBAD: int -ELIBSCN: int -ELIBMAX: int -ELIBEXEC: int EILSEQ: int -ERESTART: int -ESTRPIPE: int EUSERS: int ENOTSOCK: int EDESTADDRREQ: int @@ -119,40 +86,135 @@ EHOSTUNREACH: int EALREADY: int EINPROGRESS: int ESTALE: int -EUCLEAN: int -ENOTNAM: int -ENAVAIL: int -EISNAM: int -EREMOTEIO: int EDQUOT: int ECANCELED: int # undocumented -EKEYEXPIRED: int # undocumented -EKEYREJECTED: int # undocumented -EKEYREVOKED: int # undocumented -EMEDIUMTYPE: int # undocumented -ENOKEY: int # undocumented -ENOMEDIUM: int # undocumented ENOTRECOVERABLE: int # undocumented EOWNERDEAD: int # undocumented -ERFKILL: int # undocumented -EAUTH: int # undocumented -EBADARCH: int # undocumented -EBADEXEC: int # undocumented -EBADMACHO: int # undocumented -EBADRPC: int # undocumented -EDEVERR: int # undocumented -EFTYPE: int # undocumented -EL: int # undocumented -ELOCKUNMAPPED: int # undocumented -ENEEDAUTH: int # undocumented -ENOATTR: int # undocumented -ENOPOLICY: int # undocumented -ENOTACTIVE: int # undocumented -EPROCLIM: int # undocumented -EPROCUNAVAIL: int # undocumented -EPROGMISMATCH: int # undocumented -EPROGUNAVAIL: int # undocumented -EPWROFF: int # undocumented -EQFULL: int # undocumented -ERPCMISMATCH: int # undocumented -ESHLIBVERS: int # undocumented + +if sys.platform != "win32": + ENOTBLK: int + EMULTIHOP: int + # All of the below are undocumented + EAUTH: int + EBADARCH: int + EBADEXEC: int + EBADMACHO: int + EBADRPC: int + EDEVERR: int + EFTYPE: int + ENEEDAUTH: int + ENOATTR: int + ENOPOLICY: int + EPROCLIM: int + EPROCUNAVAIL: int + EPROGMISMATCH: int + EPROGUNAVAIL: int + EPWROFF: int + ERPCMISMATCH: int + ESHLIBVERS: int + + if sys.platform != "darwin" or sys.version_info >= (3, 11): + EQFULL: int # undocumented + +if sys.platform != "darwin": + EDEADLOCK: int + +if sys.platform != "win32" and sys.platform != "darwin": + ECHRNG: int + EL2NSYNC: int + EL3HLT: int + EL3RST: int + ELNRNG: int + EUNATCH: int + ENOCSI: int + EL2HLT: int + EBADE: int + EBADR: int + EXFULL: int + ENOANO: int + EBADRQC: int + EBADSLT: int + EBFONT: int + ENONET: int + ENOPKG: int + EADV: int + ESRMNT: int + ECOMM: int + EDOTDOT: int + ENOTUNIQ: int + EBADFD: int + EREMCHG: int + ELIBACC: int + ELIBBAD: int + ELIBSCN: int + ELIBMAX: int + ELIBEXEC: int + ERESTART: int + ESTRPIPE: int + EUCLEAN: int + ENOTNAM: int + ENAVAIL: int + EISNAM: int + EREMOTEIO: int + # All of the below are undocumented + EKEYEXPIRED: int + EKEYREJECTED: int + EKEYREVOKED: int + EMEDIUMTYPE: int + ENOKEY: int + ENOMEDIUM: int + ERFKILL: int + EL: int + ELOCKUNMAPPED: int + ENOTACTIVE: int + +if sys.platform == "win32": + # All of these are undocumented + WSABASEERR: int + WSAEACCES: int + WSAEADDRINUSE: int + WSAEADDRNOTAVAIL: int + WSAEAFNOSUPPORT: int + WSAEALREADY: int + WSAEBADF: int + WSAECONNABORTED: int + WSAECONNREFUSED: int + WSAECONNRESET: int + WSAEDESTADDRREQ: int + WSAEDISCON: int + WSAEDQUOT: int + WSAEFAULT: int + WSAEHOSTDOWN: int + WSAEHOSTUNREACH: int + WSAEINPROGRESS: int + WSAEINTR: int + WSAEINVAL: int + WSAEISCONN: int + WSAELOOP: int + WSAEMFILE: int + WSAEMSGSIZE: int + WSAENAMETOOLONG: int + WSAENETDOWN: int + WSAENETRESET: int + WSAENETUNREACH: int + WSAENOBUFS: int + WSAENOPROTOOPT: int + WSAENOTCONN: int + WSAENOTEMPTY: int + WSAENOTSOCK: int + WSAEOPNOTSUPP: int + WSAEPFNOSUPPORT: int + WSAEPROCLIM: int + WSAEPROTONOSUPPORT: int + WSAEPROTOTYPE: int + WSAEREMOTE: int + WSAESHUTDOWN: int + WSAESOCKTNOSUPPORT: int + WSAESTALE: int + WSAETIMEDOUT: int + WSAETOOMANYREFS: int + WSAEUSERS: int + WSAEWOULDBLOCK: int + WSANOTINITIALISED: int + WSASYSNOTREADY: int + WSAVERNOTSUPPORTED: int diff --git a/mypy/typeshed/stdlib/http/cookiejar.pyi b/mypy/typeshed/stdlib/http/cookiejar.pyi index 83da7faaf0fc..af33472a32e3 100644 --- a/mypy/typeshed/stdlib/http/cookiejar.pyi +++ b/mypy/typeshed/stdlib/http/cookiejar.pyi @@ -53,7 +53,8 @@ class FileCookieJar(CookieJar): def revert(self, filename: str | None = ..., ignore_discard: bool = ..., ignore_expires: bool = ...) -> None: ... class MozillaCookieJar(FileCookieJar): - header: ClassVar[str] # undocumented + if sys.version_info < (3, 10): + header: ClassVar[str] # undocumented class LWPCookieJar(FileCookieJar): def as_lwp_str(self, ignore_discard: bool = ..., ignore_expires: bool = ...) -> str: ... # undocumented diff --git a/mypy/typeshed/stdlib/imaplib.pyi b/mypy/typeshed/stdlib/imaplib.pyi index b082100774c0..347fee386717 100644 --- a/mypy/typeshed/stdlib/imaplib.pyi +++ b/mypy/typeshed/stdlib/imaplib.pyi @@ -19,9 +19,9 @@ _CommandResults: TypeAlias = tuple[str, list[Any]] _AnyResponseData: TypeAlias = list[None] | list[bytes | tuple[bytes, bytes]] class IMAP4: - error: type[Exception] - abort: type[Exception] - readonly: type[Exception] + class error(Exception): ... + class abort(error): ... + class readonly(abort): ... mustquote: Pattern[str] debug: int state: str @@ -55,7 +55,7 @@ class IMAP4: def socket(self) -> _socket: ... def recent(self) -> _CommandResults: ... def response(self, code: str) -> _CommandResults: ... - def append(self, mailbox: str, flags: str, date_time: str, message: str) -> str: ... + def append(self, mailbox: str, flags: str, date_time: str, message: bytes) -> str: ... def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ... def capability(self) -> _CommandResults: ... def check(self) -> _CommandResults: ... @@ -171,5 +171,5 @@ class _Authenticator: def Internaldate2tuple(resp: bytes) -> time.struct_time: ... def Int2AP(num: int) -> str: ... -def ParseFlags(resp: str) -> tuple[str, ...]: ... +def ParseFlags(resp: bytes) -> tuple[bytes, ...]: ... def Time2Internaldate(date_time: float | time.struct_time | str) -> str: ... diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 38d928f43c9a..53c0c0f6f08e 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -261,12 +261,14 @@ def getsource(object: _SourceObjectType) -> str: ... def cleandoc(doc: str) -> str: ... def indentsize(line: str) -> int: ... +_IntrospectableCallable: TypeAlias = Callable[..., Any] + # # Introspecting callables with the Signature object # if sys.version_info >= (3, 10): def signature( - obj: Callable[..., Any], + obj: _IntrospectableCallable, *, follow_wrapped: bool = ..., globals: Mapping[str, Any] | None = ..., @@ -275,7 +277,7 @@ if sys.version_info >= (3, 10): ) -> Signature: ... else: - def signature(obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Signature: ... + def signature(obj: _IntrospectableCallable, *, follow_wrapped: bool = ...) -> Signature: ... class _void: ... class _empty: ... @@ -298,7 +300,7 @@ class Signature: @classmethod def from_callable( cls: type[Self], - obj: Callable[..., Any], + obj: _IntrospectableCallable, *, follow_wrapped: bool = ..., globals: Mapping[str, Any] | None = ..., @@ -307,13 +309,13 @@ class Signature: ) -> Self: ... else: @classmethod - def from_callable(cls: type[Self], obj: Callable[..., Any], *, follow_wrapped: bool = ...) -> Self: ... + def from_callable(cls: type[Self], obj: _IntrospectableCallable, *, follow_wrapped: bool = ...) -> Self: ... def __eq__(self, other: object) -> bool: ... if sys.version_info >= (3, 10): def get_annotations( - obj: Callable[..., Any] | type[Any] | ModuleType, + obj: Callable[..., object] | type[Any] | ModuleType, *, globals: Mapping[str, Any] | None = ..., locals: Mapping[str, Any] | None = ..., @@ -453,8 +455,8 @@ class ClosureVars(NamedTuple): builtins: Mapping[str, Any] unbound: AbstractSet[str] -def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ... -def unwrap(func: Callable[..., Any], *, stop: Callable[[Any], Any] | None = ...) -> Any: ... +def getclosurevars(func: _IntrospectableCallable) -> ClosureVars: ... +def unwrap(func: Callable[..., Any], *, stop: Callable[[Callable[..., Any]], Any] | None = ...) -> Any: ... # # The interpreter stack diff --git a/mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi b/mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi index 34df53994c92..e9da31ed1a0a 100644 --- a/mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi +++ b/mypy/typeshed/stdlib/lib2to3/pgen2/tokenize.pyi @@ -78,7 +78,7 @@ if sys.version_info >= (3, 7): __all__ += ["COLONEQUAL"] _Coord: TypeAlias = tuple[int, int] -_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], None] +_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], object] _TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str] class TokenError(Exception): ... diff --git a/mypy/typeshed/stdlib/multiprocessing/__init__.pyi b/mypy/typeshed/stdlib/multiprocessing/__init__.pyi index 41af971bc619..4359b6c080aa 100644 --- a/mypy/typeshed/stdlib/multiprocessing/__init__.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/__init__.pyi @@ -1,18 +1,12 @@ import sys -from collections.abc import Callable, Iterable -from logging import Logger -from multiprocessing import connection, context, pool, reduction as reducer, synchronize +from multiprocessing import context, reduction as reducer, synchronize from multiprocessing.context import ( AuthenticationError as AuthenticationError, - BaseContext, BufferTooShort as BufferTooShort, - DefaultContext, Process as Process, ProcessError as ProcessError, - SpawnContext, TimeoutError as TimeoutError, ) -from multiprocessing.managers import SyncManager from multiprocessing.process import active_children as active_children, current_process as current_process # These are technically functions that return instances of these Queue classes. @@ -20,15 +14,12 @@ from multiprocessing.process import active_children as active_children, current_ # multiprocessing.queues or the aliases defined below. See #4266 for discussion. from multiprocessing.queues import JoinableQueue as JoinableQueue, Queue as Queue, SimpleQueue as SimpleQueue from multiprocessing.spawn import freeze_support as freeze_support -from typing import Any, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing import TypeVar +from typing_extensions import TypeAlias if sys.version_info >= (3, 8): from multiprocessing.process import parent_process as parent_process -if sys.platform != "win32": - from multiprocessing.context import ForkContext, ForkServerContext - __all__ = [ "Array", "AuthenticationError", @@ -92,60 +83,29 @@ _LockType: TypeAlias = synchronize.Lock _RLockType: TypeAlias = synchronize.RLock _SemaphoreType: TypeAlias = synchronize.Semaphore -# N.B. The functions below are generated at runtime by partially applying -# multiprocessing.context.BaseContext's methods, so the two signatures should -# be identical (modulo self). - -# Synchronization primitives -_LockLike: TypeAlias = synchronize.Lock | synchronize.RLock +# These functions (really bound methods) +# are all autogenerated at runtime here: https://github.com/python/cpython/blob/600c65c094b0b48704d8ec2416930648052ba715/Lib/multiprocessing/__init__.py#L23 RawValue = context._default_context.RawValue RawArray = context._default_context.RawArray Value = context._default_context.Value Array = context._default_context.Array - -def Barrier(parties: int, action: Callable[..., Any] | None = ..., timeout: float | None = ...) -> _BarrierType: ... -def BoundedSemaphore(value: int = ...) -> _BoundedSemaphoreType: ... -def Condition(lock: _LockLike | None = ...) -> _ConditionType: ... -def Event() -> _EventType: ... -def Lock() -> _LockType: ... -def RLock() -> _RLockType: ... -def Semaphore(value: int = ...) -> _SemaphoreType: ... -def Pipe(duplex: bool = ...) -> tuple[connection.Connection, connection.Connection]: ... -def Pool( - processes: int | None = ..., - initializer: Callable[..., Any] | None = ..., - initargs: Iterable[Any] = ..., - maxtasksperchild: int | None = ..., -) -> pool.Pool: ... - -# ----- multiprocessing function stubs ----- -def allow_connection_pickling() -> None: ... -def cpu_count() -> int: ... -def get_logger() -> Logger: ... -def log_to_stderr(level: str | int | None = ...) -> Logger: ... -def Manager() -> SyncManager: ... -def set_executable(executable: str) -> None: ... -def set_forkserver_preload(module_names: list[str]) -> None: ... -def get_all_start_methods() -> list[str]: ... -def get_start_method(allow_none: bool = ...) -> str | None: ... -def set_start_method(method: str, force: bool | None = ...) -> None: ... - -if sys.platform != "win32": - @overload - def get_context(method: None = ...) -> DefaultContext: ... - @overload - def get_context(method: Literal["spawn"]) -> SpawnContext: ... - @overload - def get_context(method: Literal["fork"]) -> ForkContext: ... - @overload - def get_context(method: Literal["forkserver"]) -> ForkServerContext: ... - @overload - def get_context(method: str) -> BaseContext: ... - -else: - @overload - def get_context(method: None = ...) -> DefaultContext: ... - @overload - def get_context(method: Literal["spawn"]) -> SpawnContext: ... - @overload - def get_context(method: str) -> BaseContext: ... +Barrier = context._default_context.Barrier +BoundedSemaphore = context._default_context.BoundedSemaphore +Condition = context._default_context.Condition +Event = context._default_context.Event +Lock = context._default_context.Lock +RLock = context._default_context.RLock +Semaphore = context._default_context.Semaphore +Pipe = context._default_context.Pipe +Pool = context._default_context.Pool +allow_connection_pickling = context._default_context.allow_connection_pickling +cpu_count = context._default_context.cpu_count +get_logger = context._default_context.get_logger +log_to_stderr = context._default_context.log_to_stderr +Manager = context._default_context.Manager +set_executable = context._default_context.set_executable +set_forkserver_preload = context._default_context.set_forkserver_preload +get_all_start_methods = context._default_context.get_all_start_methods +get_start_method = context._default_context.get_start_method +set_start_method = context._default_context.set_start_method +get_context = context._default_context.get_context diff --git a/mypy/typeshed/stdlib/multiprocessing/connection.pyi b/mypy/typeshed/stdlib/multiprocessing/connection.pyi index 7b227a697abe..489e8bd9a9f1 100644 --- a/mypy/typeshed/stdlib/multiprocessing/connection.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/connection.pyi @@ -58,4 +58,4 @@ def wait( object_list: Iterable[Connection | socket.socket | int], timeout: float | None = ... ) -> list[Connection | socket.socket | int]: ... def Client(address: _Address, family: str | None = ..., authkey: bytes | None = ...) -> Connection: ... -def Pipe(duplex: bool = ...) -> tuple[Connection, Connection]: ... +def Pipe(duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/context.pyi b/mypy/typeshed/stdlib/multiprocessing/context.pyi index d618d1028112..ed52325915c4 100644 --- a/mypy/typeshed/stdlib/multiprocessing/context.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/context.pyi @@ -5,6 +5,8 @@ from collections.abc import Callable, Iterable, Sequence from ctypes import _CData from logging import Logger from multiprocessing import queues, synchronize +from multiprocessing.connection import _ConnectionBase +from multiprocessing.managers import SyncManager from multiprocessing.pool import Pool as _Pool from multiprocessing.process import BaseProcess from multiprocessing.sharedctypes import SynchronizedArray, SynchronizedBase @@ -42,12 +44,10 @@ class BaseContext: @staticmethod def active_children() -> list[BaseProcess]: ... def cpu_count(self) -> int: ... - # TODO: change return to SyncManager once a stub exists in multiprocessing.managers - def Manager(self) -> Any: ... - # TODO: change return to Pipe once a stub exists in multiprocessing.connection - def Pipe(self, duplex: bool = ...) -> Any: ... + def Manager(self) -> SyncManager: ... + def Pipe(self, duplex: bool = ...) -> tuple[_ConnectionBase, _ConnectionBase]: ... def Barrier( - self, parties: int, action: Callable[..., Any] | None = ..., timeout: float | None = ... + self, parties: int, action: Callable[..., object] | None = ..., timeout: float | None = ... ) -> synchronize.Barrier: ... def BoundedSemaphore(self, value: int = ...) -> synchronize.BoundedSemaphore: ... def Condition(self, lock: _LockLike | None = ...) -> synchronize.Condition: ... @@ -61,7 +61,7 @@ class BaseContext: def Pool( self, processes: int | None = ..., - initializer: Callable[..., Any] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ..., maxtasksperchild: int | None = ..., ) -> _Pool: ... @@ -120,7 +120,10 @@ class BaseContext: @overload def get_context(self, method: str) -> BaseContext: ... - def get_start_method(self, allow_none: bool = ...) -> str: ... + @overload + def get_start_method(self, allow_none: Literal[False] = ...) -> str: ... + @overload + def get_start_method(self, allow_none: bool) -> str | None: ... def set_start_method(self, method: str | None, force: bool = ...) -> None: ... @property def reducer(self) -> str: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi b/mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi index bbddfd16ded7..5d289c058e03 100644 --- a/mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/dummy/__init__.pyi @@ -3,6 +3,15 @@ import threading import weakref from collections.abc import Callable, Iterable, Mapping, Sequence from queue import Queue as Queue +from threading import ( + Barrier as Barrier, + BoundedSemaphore as BoundedSemaphore, + Condition as Condition, + Event as Event, + Lock as Lock, + RLock as RLock, + Semaphore as Semaphore, +) from typing import Any from typing_extensions import Literal @@ -28,13 +37,6 @@ __all__ = [ ] JoinableQueue = Queue -Barrier = threading.Barrier -BoundedSemaphore = threading.BoundedSemaphore -Condition = threading.Condition -Event = threading.Event -Lock = threading.Lock -RLock = threading.RLock -Semaphore = threading.Semaphore class DummyProcess(threading.Thread): _children: weakref.WeakKeyDictionary[Any, Any] @@ -46,7 +48,7 @@ class DummyProcess(threading.Thread): def __init__( self, group: Any = ..., - target: Callable[..., Any] | None = ..., + target: Callable[..., object] | None = ..., name: str | None = ..., args: Iterable[Any] = ..., kwargs: Mapping[str, Any] = ..., @@ -67,8 +69,10 @@ class Value: def Array(typecode: Any, sequence: Sequence[Any], lock: Any = ...) -> array.array[Any]: ... def Manager() -> Any: ... -def Pool(processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...) -> Any: ... +def Pool(processes: int | None = ..., initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ...) -> Any: ... def active_children() -> list[Any]: ... -def current_process() -> threading.Thread: ... + +current_process = threading.current_thread + def freeze_support() -> None: ... def shutdown() -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/managers.pyi b/mypy/typeshed/stdlib/multiprocessing/managers.pyi index 212ffcbf5a3a..5537ea937bae 100644 --- a/mypy/typeshed/stdlib/multiprocessing/managers.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/managers.pyi @@ -148,7 +148,7 @@ class BaseManager: def get_server(self) -> Server: ... def connect(self) -> None: ... - def start(self, initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...) -> None: ... + def start(self, initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ...) -> None: ... def shutdown(self) -> None: ... # only available after start() was called def join(self, timeout: float | None = ...) -> None: ... # undocumented @property @@ -157,7 +157,7 @@ class BaseManager: def register( cls, typeid: str, - callable: Callable[..., Any] | None = ..., + callable: Callable[..., object] | None = ..., proxytype: Any = ..., exposed: Sequence[str] | None = ..., method_to_typeid: Mapping[str, str] | None = ..., diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index c0d01e98dfae..2b97e16f0525 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -16,14 +16,14 @@ _T = TypeVar("_T") class ApplyResult(Generic[_T]): if sys.version_info >= (3, 8): def __init__( - self, pool: Pool, callback: Callable[[_T], None] | None, error_callback: Callable[[BaseException], None] | None + self, pool: Pool, callback: Callable[[_T], object] | None, error_callback: Callable[[BaseException], object] | None ) -> None: ... else: def __init__( self, cache: dict[int, ApplyResult[Any]], - callback: Callable[[_T], None] | None, - error_callback: Callable[[BaseException], None] | None, + callback: Callable[[_T], object] | None, + error_callback: Callable[[BaseException], object] | None, ) -> None: ... def get(self, timeout: float | None = ...) -> _T: ... @@ -43,8 +43,8 @@ class MapResult(ApplyResult[list[_T]]): pool: Pool, chunksize: int, length: int, - callback: Callable[[list[_T]], None] | None, - error_callback: Callable[[BaseException], None] | None, + callback: Callable[[list[_T]], object] | None, + error_callback: Callable[[BaseException], object] | None, ) -> None: ... else: def __init__( @@ -52,8 +52,8 @@ class MapResult(ApplyResult[list[_T]]): cache: dict[int, ApplyResult[Any]], chunksize: int, length: int, - callback: Callable[[list[_T]], None] | None, - error_callback: Callable[[BaseException], None] | None, + callback: Callable[[list[_T]], object] | None, + error_callback: Callable[[BaseException], object] | None, ) -> None: ... class IMapIterator(Iterator[_T]): @@ -72,7 +72,7 @@ class Pool: def __init__( self, processes: int | None = ..., - initializer: Callable[..., None] | None = ..., + initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ..., maxtasksperchild: int | None = ..., context: Any | None = ..., @@ -83,8 +83,8 @@ class Pool: func: Callable[..., _T], args: Iterable[Any] = ..., kwds: Mapping[str, Any] = ..., - callback: Callable[[_T], None] | None = ..., - error_callback: Callable[[BaseException], None] | None = ..., + callback: Callable[[_T], object] | None = ..., + error_callback: Callable[[BaseException], object] | None = ..., ) -> AsyncResult[_T]: ... def map(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> list[_T]: ... def map_async( @@ -92,8 +92,8 @@ class Pool: func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ..., - callback: Callable[[_T], None] | None = ..., - error_callback: Callable[[BaseException], None] | None = ..., + callback: Callable[[_T], object] | None = ..., + error_callback: Callable[[BaseException], object] | None = ..., ) -> MapResult[_T]: ... def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S], chunksize: int | None = ...) -> IMapIterator[_T]: ... def imap_unordered( @@ -105,8 +105,8 @@ class Pool: func: Callable[..., _T], iterable: Iterable[Iterable[Any]], chunksize: int | None = ..., - callback: Callable[[_T], None] | None = ..., - error_callback: Callable[[BaseException], None] | None = ..., + callback: Callable[[_T], object] | None = ..., + error_callback: Callable[[BaseException], object] | None = ..., ) -> AsyncResult[list[_T]]: ... def close(self) -> None: ... def terminate(self) -> None: ... @@ -118,7 +118,7 @@ class Pool: class ThreadPool(Pool): def __init__( - self, processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ... + self, processes: int | None = ..., initializer: Callable[..., object] | None = ..., initargs: Iterable[Any] = ... ) -> None: ... # undocumented diff --git a/mypy/typeshed/stdlib/multiprocessing/process.pyi b/mypy/typeshed/stdlib/multiprocessing/process.pyi index 1601decbbebc..f903cef6fa72 100644 --- a/mypy/typeshed/stdlib/multiprocessing/process.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/process.pyi @@ -15,7 +15,7 @@ class BaseProcess: def __init__( self, group: None = ..., - target: Callable[..., Any] | None = ..., + target: Callable[..., object] | None = ..., name: str | None = ..., args: Iterable[Any] = ..., kwargs: Mapping[str, Any] = ..., diff --git a/mypy/typeshed/stdlib/multiprocessing/synchronize.pyi b/mypy/typeshed/stdlib/multiprocessing/synchronize.pyi index e93d6c58b5cf..7a86935f7d18 100644 --- a/mypy/typeshed/stdlib/multiprocessing/synchronize.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/synchronize.pyi @@ -4,7 +4,6 @@ from collections.abc import Callable from contextlib import AbstractContextManager from multiprocessing.context import BaseContext from types import TracebackType -from typing import Any from typing_extensions import TypeAlias __all__ = ["Lock", "RLock", "Semaphore", "BoundedSemaphore", "Condition", "Event"] @@ -13,7 +12,7 @@ _LockLike: TypeAlias = Lock | RLock class Barrier(threading.Barrier): def __init__( - self, parties: int, action: Callable[..., Any] | None = ..., timeout: float | None = ..., *ctx: BaseContext + self, parties: int, action: Callable[[], object] | None = ..., timeout: float | None = ..., *ctx: BaseContext ) -> None: ... class BoundedSemaphore(Semaphore): diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 68ea2948f17e..68c7634272e3 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -213,8 +213,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): decodevalue: _EnvironCodeFunc[AnyStr], ) -> None: ... else: - putenv: Callable[[AnyStr, AnyStr], None] - unsetenv: Callable[[AnyStr, AnyStr], None] + putenv: Callable[[AnyStr, AnyStr], object] + unsetenv: Callable[[AnyStr, AnyStr], object] def __init__( self, data: MutableMapping[AnyStr, AnyStr], @@ -222,8 +222,8 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): decodekey: _EnvironCodeFunc[AnyStr], encodevalue: _EnvironCodeFunc[AnyStr], decodevalue: _EnvironCodeFunc[AnyStr], - putenv: Callable[[AnyStr, AnyStr], None], - unsetenv: Callable[[AnyStr, AnyStr], None], + putenv: Callable[[AnyStr, AnyStr], object], + unsetenv: Callable[[AnyStr, AnyStr], object], ) -> None: ... def setdefault(self, key: AnyStr, value: AnyStr) -> AnyStr: ... # type: ignore[override] diff --git a/mypy/typeshed/stdlib/pickle.pyi b/mypy/typeshed/stdlib/pickle.pyi index 088adc8196c2..9a94e9eced3c 100644 --- a/mypy/typeshed/stdlib/pickle.pyi +++ b/mypy/typeshed/stdlib/pickle.pyi @@ -145,7 +145,7 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_reducedtype: TypeAlias = Union[ +_ReducedType: TypeAlias = Union[ str, tuple[Callable[..., Any], tuple[Any, ...]], tuple[Callable[..., Any], tuple[Any, ...], Any], @@ -155,7 +155,7 @@ _reducedtype: TypeAlias = Union[ class Pickler: fast: bool - dispatch_table: Mapping[type, Callable[[Any], _reducedtype]] + dispatch_table: Mapping[type, Callable[[Any], _ReducedType]] bin: bool # undocumented dispatch: ClassVar[dict[type, Callable[[Unpickler, Any], None]]] # undocumented, _Pickler only diff --git a/mypy/typeshed/stdlib/pkgutil.pyi b/mypy/typeshed/stdlib/pkgutil.pyi index 5a93a9f86812..f91ab78ff35d 100644 --- a/mypy/typeshed/stdlib/pkgutil.pyi +++ b/mypy/typeshed/stdlib/pkgutil.pyi @@ -41,7 +41,7 @@ def iter_importers(fullname: str = ...) -> Iterator[MetaPathFinder | PathEntryFi def iter_modules(path: Iterable[str] | None = ..., prefix: str = ...) -> Iterator[ModuleInfo]: ... def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented def walk_packages( - path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], None] | None = ... + path: Iterable[str] | None = ..., prefix: str = ..., onerror: Callable[[str], object] | None = ... ) -> Iterator[ModuleInfo]: ... def get_data(package: str, resource: str) -> bytes | None: ... diff --git a/mypy/typeshed/stdlib/pydoc.pyi b/mypy/typeshed/stdlib/pydoc.pyi index 6ea4a74a9d28..abcffc31111a 100644 --- a/mypy/typeshed/stdlib/pydoc.pyi +++ b/mypy/typeshed/stdlib/pydoc.pyi @@ -202,8 +202,6 @@ def locate(path: str, forceload: bool = ...) -> object: ... text: TextDoc html: HTMLDoc -class _OldStyleClass: ... - def resolve(thing: str | object, forceload: bool = ...) -> tuple[object, str] | None: ... def render_doc(thing: str | object, title: str = ..., forceload: bool = ..., renderer: Doc | None = ...) -> str: ... def doc(thing: str | object, title: str = ..., forceload: bool = ..., output: SupportsWrite[str] | None = ...) -> None: ... @@ -238,10 +236,10 @@ class ModuleScanner: quit: bool def run( self, - callback: Callable[[str | None, str, str], None], + callback: Callable[[str | None, str, str], object], key: str | None = ..., - completer: Callable[[], None] | None = ..., - onerror: Callable[[str], None] | None = ..., + completer: Callable[[], object] | None = ..., + onerror: Callable[[str], object] | None = ..., ) -> None: ... def apropos(key: str) -> None: ... diff --git a/mypy/typeshed/stdlib/shelve.pyi b/mypy/typeshed/stdlib/shelve.pyi index 2a211ab34208..c801ecd3f186 100644 --- a/mypy/typeshed/stdlib/shelve.pyi +++ b/mypy/typeshed/stdlib/shelve.pyi @@ -2,7 +2,7 @@ from _typeshed import Self from collections.abc import Iterator, MutableMapping from dbm import _TFlags from types import TracebackType -from typing import TypeVar, overload +from typing import Any, TypeVar, overload __all__ = ["Shelf", "BsdDbShelf", "DbfilenameShelf", "open"] @@ -40,4 +40,4 @@ class BsdDbShelf(Shelf[_VT]): class DbfilenameShelf(Shelf[_VT]): def __init__(self, filename: str, flag: _TFlags = ..., protocol: int | None = ..., writeback: bool = ...) -> None: ... -def open(filename: str, flag: _TFlags = ..., protocol: int | None = ..., writeback: bool = ...) -> Shelf[object]: ... +def open(filename: str, flag: _TFlags = ..., protocol: int | None = ..., writeback: bool = ...) -> Shelf[Any]: ... diff --git a/mypy/typeshed/stdlib/shutil.pyi b/mypy/typeshed/stdlib/shutil.pyi index ae62ea4b658f..b6d0b9dbf7f3 100644 --- a/mypy/typeshed/stdlib/shutil.pyi +++ b/mypy/typeshed/stdlib/shutil.pyi @@ -67,7 +67,7 @@ if sys.version_info >= (3, 8): dst: StrPath, symlinks: bool = ..., ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ..., - copy_function: Callable[[str, str], None] = ..., + copy_function: Callable[[str, str], object] = ..., ignore_dangling_symlinks: bool = ..., dirs_exist_ok: bool = ..., ) -> _PathReturn: ... @@ -78,7 +78,7 @@ else: dst: StrPath, symlinks: bool = ..., ignore: None | Callable[[str, list[str]], Iterable[str]] | Callable[[StrPath, list[str]], Iterable[str]] = ..., - copy_function: Callable[[str, str], None] = ..., + copy_function: Callable[[str, str], object] = ..., ignore_dangling_symlinks: bool = ..., ) -> _PathReturn: ... @@ -94,7 +94,7 @@ if sys.version_info >= (3, 11): else: def rmtree(path: StrOrBytesPath, ignore_errors: bool = ..., onerror: Callable[[Any, Any, Any], Any] | None = ...) -> None: ... -_CopyFn: TypeAlias = Callable[[str, str], None] | Callable[[StrPath, StrPath], None] +_CopyFn: TypeAlias = Callable[[str, str], object] | Callable[[StrPath, StrPath], object] # N.B. shutil.move appears to take bytes arguments, however, # this does not work when dst is (or is within) an existing directory. diff --git a/mypy/typeshed/stdlib/signal.pyi b/mypy/typeshed/stdlib/signal.pyi index 893d9d45e4b1..a9d6ca28f8d7 100644 --- a/mypy/typeshed/stdlib/signal.pyi +++ b/mypy/typeshed/stdlib/signal.pyi @@ -4,7 +4,7 @@ from collections.abc import Callable, Iterable from enum import IntEnum from types import FrameType from typing import Any, Union -from typing_extensions import Final, TypeAlias, final +from typing_extensions import Final, Never, TypeAlias, final NSIG: int @@ -64,7 +64,7 @@ SIG_IGN: Handlers _SIGNUM: TypeAlias = int | Signals _HANDLER: TypeAlias = Union[Callable[[int, FrameType | None], Any], int, Handlers, None] -def default_int_handler(__signalnum: int, __frame: FrameType | None) -> None: ... +def default_int_handler(__signalnum: int, __frame: FrameType | None) -> Never: ... if sys.version_info >= (3, 10): # arguments changed in 3.10.2 def getsignal(signalnum: _SIGNUM) -> _HANDLER: ... diff --git a/mypy/typeshed/stdlib/smtpd.pyi b/mypy/typeshed/stdlib/smtpd.pyi index fc5a1cb62b16..f2de6c155c07 100644 --- a/mypy/typeshed/stdlib/smtpd.pyi +++ b/mypy/typeshed/stdlib/smtpd.pyi @@ -42,7 +42,7 @@ class SMTPChannel(asynchat.async_chat): conn: socket.socket, addr: Any, data_size_limit: int = ..., - map: asyncore._maptype | None = ..., + map: asyncore._MapType | None = ..., enable_SMTPUTF8: bool = ..., decode_data: bool = ..., ) -> None: ... @@ -72,7 +72,7 @@ class SMTPServer(asyncore.dispatcher): localaddr: _Address, remoteaddr: _Address, data_size_limit: int = ..., - map: asyncore._maptype | None = ..., + map: asyncore._MapType | None = ..., enable_SMTPUTF8: bool = ..., decode_data: bool = ..., ) -> None: ... diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index d84fd66b87cf..0b06e888aeb6 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -12,21 +12,15 @@ from typing_extensions import Literal import _socket from _socket import ( _FD, - EAI_ADDRFAMILY as EAI_ADDRFAMILY, EAI_AGAIN as EAI_AGAIN, EAI_BADFLAGS as EAI_BADFLAGS, - EAI_BADHINTS as EAI_BADHINTS, EAI_FAIL as EAI_FAIL, EAI_FAMILY as EAI_FAMILY, - EAI_MAX as EAI_MAX, EAI_MEMORY as EAI_MEMORY, EAI_NODATA as EAI_NODATA, EAI_NONAME as EAI_NONAME, - EAI_OVERFLOW as EAI_OVERFLOW, - EAI_PROTOCOL as EAI_PROTOCOL, EAI_SERVICE as EAI_SERVICE, EAI_SOCKTYPE as EAI_SOCKTYPE, - EAI_SYSTEM as EAI_SYSTEM, INADDR_ALLHOSTS_GROUP as INADDR_ALLHOSTS_GROUP, INADDR_ANY as INADDR_ANY, INADDR_BROADCAST as INADDR_BROADCAST, @@ -35,88 +29,32 @@ from _socket import ( INADDR_NONE as INADDR_NONE, INADDR_UNSPEC_GROUP as INADDR_UNSPEC_GROUP, IP_ADD_MEMBERSHIP as IP_ADD_MEMBERSHIP, - IP_DEFAULT_MULTICAST_LOOP as IP_DEFAULT_MULTICAST_LOOP, - IP_DEFAULT_MULTICAST_TTL as IP_DEFAULT_MULTICAST_TTL, IP_DROP_MEMBERSHIP as IP_DROP_MEMBERSHIP, IP_HDRINCL as IP_HDRINCL, - IP_MAX_MEMBERSHIPS as IP_MAX_MEMBERSHIPS, IP_MULTICAST_IF as IP_MULTICAST_IF, IP_MULTICAST_LOOP as IP_MULTICAST_LOOP, IP_MULTICAST_TTL as IP_MULTICAST_TTL, IP_OPTIONS as IP_OPTIONS, IP_RECVDSTADDR as IP_RECVDSTADDR, - IP_RECVOPTS as IP_RECVOPTS, - IP_RECVRETOPTS as IP_RECVRETOPTS, - IP_RETOPTS as IP_RETOPTS, IP_TOS as IP_TOS, - IP_TRANSPARENT as IP_TRANSPARENT, IP_TTL as IP_TTL, IPPORT_RESERVED as IPPORT_RESERVED, IPPORT_USERRESERVED as IPPORT_USERRESERVED, - IPPROTO_AH as IPPROTO_AH, - IPPROTO_BIP as IPPROTO_BIP, - IPPROTO_DSTOPTS as IPPROTO_DSTOPTS, - IPPROTO_EGP as IPPROTO_EGP, - IPPROTO_EON as IPPROTO_EON, - IPPROTO_ESP as IPPROTO_ESP, - IPPROTO_FRAGMENT as IPPROTO_FRAGMENT, - IPPROTO_GGP as IPPROTO_GGP, - IPPROTO_GRE as IPPROTO_GRE, - IPPROTO_HELLO as IPPROTO_HELLO, - IPPROTO_HOPOPTS as IPPROTO_HOPOPTS, IPPROTO_ICMP as IPPROTO_ICMP, - IPPROTO_ICMPV6 as IPPROTO_ICMPV6, - IPPROTO_IDP as IPPROTO_IDP, - IPPROTO_IGMP as IPPROTO_IGMP, IPPROTO_IP as IPPROTO_IP, - IPPROTO_IPCOMP as IPPROTO_IPCOMP, - IPPROTO_IPIP as IPPROTO_IPIP, - IPPROTO_IPV4 as IPPROTO_IPV4, - IPPROTO_IPV6 as IPPROTO_IPV6, - IPPROTO_MAX as IPPROTO_MAX, - IPPROTO_MOBILE as IPPROTO_MOBILE, - IPPROTO_ND as IPPROTO_ND, - IPPROTO_NONE as IPPROTO_NONE, - IPPROTO_PIM as IPPROTO_PIM, - IPPROTO_PUP as IPPROTO_PUP, IPPROTO_RAW as IPPROTO_RAW, - IPPROTO_ROUTING as IPPROTO_ROUTING, - IPPROTO_RSVP as IPPROTO_RSVP, - IPPROTO_SCTP as IPPROTO_SCTP, IPPROTO_TCP as IPPROTO_TCP, - IPPROTO_TP as IPPROTO_TP, IPPROTO_UDP as IPPROTO_UDP, - IPPROTO_VRRP as IPPROTO_VRRP, - IPPROTO_XTP as IPPROTO_XTP, IPV6_CHECKSUM as IPV6_CHECKSUM, - IPV6_DONTFRAG as IPV6_DONTFRAG, - IPV6_DSTOPTS as IPV6_DSTOPTS, - IPV6_HOPLIMIT as IPV6_HOPLIMIT, - IPV6_HOPOPTS as IPV6_HOPOPTS, IPV6_JOIN_GROUP as IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP as IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS as IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF as IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP as IPV6_MULTICAST_LOOP, - IPV6_NEXTHOP as IPV6_NEXTHOP, - IPV6_PATHMTU as IPV6_PATHMTU, - IPV6_PKTINFO as IPV6_PKTINFO, - IPV6_RECVDSTOPTS as IPV6_RECVDSTOPTS, - IPV6_RECVHOPLIMIT as IPV6_RECVHOPLIMIT, - IPV6_RECVHOPOPTS as IPV6_RECVHOPOPTS, - IPV6_RECVPATHMTU as IPV6_RECVPATHMTU, - IPV6_RECVPKTINFO as IPV6_RECVPKTINFO, - IPV6_RECVRTHDR as IPV6_RECVRTHDR, IPV6_RECVTCLASS as IPV6_RECVTCLASS, - IPV6_RTHDR as IPV6_RTHDR, - IPV6_RTHDR_TYPE_0 as IPV6_RTHDR_TYPE_0, - IPV6_RTHDRDSTOPTS as IPV6_RTHDRDSTOPTS, IPV6_TCLASS as IPV6_TCLASS, IPV6_UNICAST_HOPS as IPV6_UNICAST_HOPS, - IPV6_USE_MIN_MTU as IPV6_USE_MIN_MTU, IPV6_V6ONLY as IPV6_V6ONLY, - IPX_TYPE as IPX_TYPE, - LOCAL_PEERCRED as LOCAL_PEERCRED, NI_DGRAM as NI_DGRAM, NI_MAXHOST as NI_MAXHOST, NI_MAXSERV as NI_MAXSERV, @@ -124,61 +62,35 @@ from _socket import ( NI_NOFQDN as NI_NOFQDN, NI_NUMERICHOST as NI_NUMERICHOST, NI_NUMERICSERV as NI_NUMERICSERV, - SCM_CREDENTIALS as SCM_CREDENTIALS, - SCM_CREDS as SCM_CREDS, - SCM_RIGHTS as SCM_RIGHTS, SHUT_RD as SHUT_RD, SHUT_RDWR as SHUT_RDWR, SHUT_WR as SHUT_WR, SO_ACCEPTCONN as SO_ACCEPTCONN, - SO_BINDTODEVICE as SO_BINDTODEVICE, SO_BROADCAST as SO_BROADCAST, SO_DEBUG as SO_DEBUG, SO_DONTROUTE as SO_DONTROUTE, SO_ERROR as SO_ERROR, - SO_EXCLUSIVEADDRUSE as SO_EXCLUSIVEADDRUSE, SO_KEEPALIVE as SO_KEEPALIVE, SO_LINGER as SO_LINGER, - SO_MARK as SO_MARK, SO_OOBINLINE as SO_OOBINLINE, - SO_PASSCRED as SO_PASSCRED, - SO_PEERCRED as SO_PEERCRED, - SO_PRIORITY as SO_PRIORITY, SO_RCVBUF as SO_RCVBUF, SO_RCVLOWAT as SO_RCVLOWAT, SO_RCVTIMEO as SO_RCVTIMEO, SO_REUSEADDR as SO_REUSEADDR, - SO_REUSEPORT as SO_REUSEPORT, - SO_SETFIB as SO_SETFIB, SO_SNDBUF as SO_SNDBUF, SO_SNDLOWAT as SO_SNDLOWAT, SO_SNDTIMEO as SO_SNDTIMEO, SO_TYPE as SO_TYPE, SO_USELOOPBACK as SO_USELOOPBACK, - SOL_ATALK as SOL_ATALK, - SOL_AX25 as SOL_AX25, - SOL_HCI as SOL_HCI, SOL_IP as SOL_IP, - SOL_IPX as SOL_IPX, - SOL_NETROM as SOL_NETROM, - SOL_ROSE as SOL_ROSE, SOL_SOCKET as SOL_SOCKET, SOL_TCP as SOL_TCP, SOL_UDP as SOL_UDP, SOMAXCONN as SOMAXCONN, - TCP_CORK as TCP_CORK, - TCP_DEFER_ACCEPT as TCP_DEFER_ACCEPT, TCP_FASTOPEN as TCP_FASTOPEN, - TCP_INFO as TCP_INFO, TCP_KEEPCNT as TCP_KEEPCNT, - TCP_KEEPIDLE as TCP_KEEPIDLE, - TCP_KEEPINTVL as TCP_KEEPINTVL, - TCP_LINGER2 as TCP_LINGER2, TCP_MAXSEG as TCP_MAXSEG, TCP_NODELAY as TCP_NODELAY, - TCP_QUICKACK as TCP_QUICKACK, - TCP_SYNCNT as TCP_SYNCNT, - TCP_WINDOW_CLAMP as TCP_WINDOW_CLAMP, SocketType as SocketType, _Address as _Address, _RetAddress as _RetAddress, @@ -208,12 +120,150 @@ from _socket import ( timeout as timeout, ) +if sys.platform != "darwin" or sys.version_info >= (3, 9): + from _socket import ( + IPV6_DONTFRAG as IPV6_DONTFRAG, + IPV6_HOPLIMIT as IPV6_HOPLIMIT, + IPV6_HOPOPTS as IPV6_HOPOPTS, + IPV6_PKTINFO as IPV6_PKTINFO, + IPV6_RECVRTHDR as IPV6_RECVRTHDR, + IPV6_RTHDR as IPV6_RTHDR, + ) + +if sys.platform != "darwin": + from _socket import SO_EXCLUSIVEADDRUSE as SO_EXCLUSIVEADDRUSE + +if sys.version_info >= (3, 10): + from _socket import IP_RECVTOS as IP_RECVTOS +elif sys.platform != "darwin" and sys.platform != "win32": + from _socket import IP_RECVTOS as IP_RECVTOS + if sys.version_info >= (3, 7): from _socket import close as close + +if sys.platform != "win32" or sys.version_info >= (3, 7): + from _socket import TCP_KEEPINTVL as TCP_KEEPINTVL + + if sys.platform != "darwin": + from _socket import TCP_KEEPIDLE as TCP_KEEPIDLE + +if sys.platform != "win32" or sys.version_info >= (3, 8): + from _socket import ( + IPPROTO_AH as IPPROTO_AH, + IPPROTO_DSTOPTS as IPPROTO_DSTOPTS, + IPPROTO_EGP as IPPROTO_EGP, + IPPROTO_ESP as IPPROTO_ESP, + IPPROTO_FRAGMENT as IPPROTO_FRAGMENT, + IPPROTO_GGP as IPPROTO_GGP, + IPPROTO_HOPOPTS as IPPROTO_HOPOPTS, + IPPROTO_ICMPV6 as IPPROTO_ICMPV6, + IPPROTO_IDP as IPPROTO_IDP, + IPPROTO_IGMP as IPPROTO_IGMP, + IPPROTO_IPV4 as IPPROTO_IPV4, + IPPROTO_IPV6 as IPPROTO_IPV6, + IPPROTO_MAX as IPPROTO_MAX, + IPPROTO_ND as IPPROTO_ND, + IPPROTO_NONE as IPPROTO_NONE, + IPPROTO_PIM as IPPROTO_PIM, + IPPROTO_PUP as IPPROTO_PUP, + IPPROTO_ROUTING as IPPROTO_ROUTING, + IPPROTO_SCTP as IPPROTO_SCTP, + ) + + if sys.platform != "darwin": + from _socket import ( + IPPROTO_CBT as IPPROTO_CBT, + IPPROTO_ICLFXBM as IPPROTO_ICLFXBM, + IPPROTO_IGP as IPPROTO_IGP, + IPPROTO_L2TP as IPPROTO_L2TP, + IPPROTO_PGM as IPPROTO_PGM, + IPPROTO_RDP as IPPROTO_RDP, + IPPROTO_ST as IPPROTO_ST, + ) +if sys.platform != "win32" and sys.platform != "darwin": + from _socket import ( + IP_TRANSPARENT as IP_TRANSPARENT, + IPPROTO_BIP as IPPROTO_BIP, + IPPROTO_MOBILE as IPPROTO_MOBILE, + IPPROTO_VRRP as IPPROTO_VRRP, + IPX_TYPE as IPX_TYPE, + SCM_CREDENTIALS as SCM_CREDENTIALS, + SO_BINDTODEVICE as SO_BINDTODEVICE, + SO_MARK as SO_MARK, + SO_PASSCRED as SO_PASSCRED, + SO_PEERCRED as SO_PEERCRED, + SO_PRIORITY as SO_PRIORITY, + SO_SETFIB as SO_SETFIB, + SOL_ATALK as SOL_ATALK, + SOL_AX25 as SOL_AX25, + SOL_HCI as SOL_HCI, + SOL_IPX as SOL_IPX, + SOL_NETROM as SOL_NETROM, + SOL_ROSE as SOL_ROSE, + TCP_CORK as TCP_CORK, + TCP_DEFER_ACCEPT as TCP_DEFER_ACCEPT, + TCP_INFO as TCP_INFO, + TCP_LINGER2 as TCP_LINGER2, + TCP_QUICKACK as TCP_QUICKACK, + TCP_SYNCNT as TCP_SYNCNT, + TCP_WINDOW_CLAMP as TCP_WINDOW_CLAMP, + ) if sys.platform != "win32": - from _socket import CMSG_LEN as CMSG_LEN, CMSG_SPACE as CMSG_SPACE, sethostname as sethostname + from _socket import ( + CMSG_LEN as CMSG_LEN, + CMSG_SPACE as CMSG_SPACE, + EAI_ADDRFAMILY as EAI_ADDRFAMILY, + EAI_BADHINTS as EAI_BADHINTS, + EAI_MAX as EAI_MAX, + EAI_OVERFLOW as EAI_OVERFLOW, + EAI_PROTOCOL as EAI_PROTOCOL, + EAI_SYSTEM as EAI_SYSTEM, + IP_DEFAULT_MULTICAST_LOOP as IP_DEFAULT_MULTICAST_LOOP, + IP_DEFAULT_MULTICAST_TTL as IP_DEFAULT_MULTICAST_TTL, + IP_MAX_MEMBERSHIPS as IP_MAX_MEMBERSHIPS, + IP_RECVOPTS as IP_RECVOPTS, + IP_RECVRETOPTS as IP_RECVRETOPTS, + IP_RETOPTS as IP_RETOPTS, + IPPROTO_EON as IPPROTO_EON, + IPPROTO_GRE as IPPROTO_GRE, + IPPROTO_HELLO as IPPROTO_HELLO, + IPPROTO_IPCOMP as IPPROTO_IPCOMP, + IPPROTO_IPIP as IPPROTO_IPIP, + IPPROTO_RSVP as IPPROTO_RSVP, + IPPROTO_TP as IPPROTO_TP, + IPPROTO_XTP as IPPROTO_XTP, + IPV6_RTHDR_TYPE_0 as IPV6_RTHDR_TYPE_0, + LOCAL_PEERCRED as LOCAL_PEERCRED, + SCM_CREDS as SCM_CREDS, + SCM_RIGHTS as SCM_RIGHTS, + SO_REUSEPORT as SO_REUSEPORT, + sethostname as sethostname, + ) + + if sys.platform != "darwin" or sys.version_info >= (3, 9): + from _socket import ( + IPV6_DSTOPTS as IPV6_DSTOPTS, + IPV6_NEXTHOP as IPV6_NEXTHOP, + IPV6_PATHMTU as IPV6_PATHMTU, + IPV6_RECVDSTOPTS as IPV6_RECVDSTOPTS, + IPV6_RECVHOPLIMIT as IPV6_RECVHOPLIMIT, + IPV6_RECVHOPOPTS as IPV6_RECVHOPOPTS, + IPV6_RECVPATHMTU as IPV6_RECVPATHMTU, + IPV6_RECVPKTINFO as IPV6_RECVPKTINFO, + IPV6_RTHDRDSTOPTS as IPV6_RTHDRDSTOPTS, + IPV6_USE_MIN_MTU as IPV6_USE_MIN_MTU, + ) + if sys.platform != "win32" or sys.version_info >= (3, 8): from _socket import if_indextoname as if_indextoname, if_nameindex as if_nameindex, if_nametoindex as if_nametoindex + +if sys.platform != "darwin": + if sys.platform != "win32" or sys.version_info >= (3, 9): + from _socket import BDADDR_ANY as BDADDR_ANY, BDADDR_LOCAL as BDADDR_LOCAL, BTPROTO_RFCOMM as BTPROTO_RFCOMM + +if sys.platform == "darwin" and sys.version_info >= (3, 10): + from _socket import TCP_KEEPALIVE as TCP_KEEPALIVE + if sys.platform == "linux": from _socket import ( ALG_OP_DECRYPT as ALG_OP_DECRYPT, @@ -315,12 +365,13 @@ if sys.platform == "linux" and sys.version_info >= (3, 7): SO_VM_SOCKETS_BUFFER_MAX_SIZE as SO_VM_SOCKETS_BUFFER_MAX_SIZE, SO_VM_SOCKETS_BUFFER_MIN_SIZE as SO_VM_SOCKETS_BUFFER_MIN_SIZE, SO_VM_SOCKETS_BUFFER_SIZE as SO_VM_SOCKETS_BUFFER_SIZE, - TCP_NOTSENT_LOWAT as TCP_NOTSENT_LOWAT, VM_SOCKETS_INVALID_VERSION as VM_SOCKETS_INVALID_VERSION, VMADDR_CID_ANY as VMADDR_CID_ANY, VMADDR_CID_HOST as VMADDR_CID_HOST, VMADDR_PORT_ANY as VMADDR_PORT_ANY, ) +if sys.platform != "win32" and sys.version_info >= (3, 7): + from _socket import TCP_NOTSENT_LOWAT as TCP_NOTSENT_LOWAT if sys.platform == "linux" and sys.version_info >= (3, 8): from _socket import ( CAN_BCM_CAN_FD_FRAME as CAN_BCM_CAN_FD_FRAME, @@ -370,7 +421,6 @@ if sys.platform == "linux" and sys.version_info >= (3, 11): from _socket import SO_INCOMING_CPU as SO_INCOMING_CPU if sys.platform == "win32": from _socket import ( - RCVALL_IPLEVEL as RCVALL_IPLEVEL, RCVALL_MAX as RCVALL_MAX, RCVALL_OFF as RCVALL_OFF, RCVALL_ON as RCVALL_ON, @@ -386,85 +436,102 @@ EAGAIN: int EWOULDBLOCK: int class AddressFamily(IntEnum): - AF_UNIX: int AF_INET: int AF_INET6: int - AF_AAL5: int - AF_ALG: int AF_APPLETALK: int - AF_ASH: int - AF_ATMPVC: int - AF_ATMSVC: int - AF_AX25: int - AF_BLUETOOTH: int - AF_BRIDGE: int - AF_CAN: int AF_DECnet: int - AF_ECONET: int AF_IPX: int - AF_IRDA: int - AF_KEY: int - AF_LINK: int - AF_LLC: int - AF_NETBEUI: int - AF_NETLINK: int - AF_NETROM: int - AF_PACKET: int - AF_PPPOX: int - AF_QIPCRTR: int - AF_RDS: int - AF_ROSE: int - AF_ROUTE: int - AF_SECURITY: int AF_SNA: int - AF_SYSTEM: int - AF_TIPC: int AF_UNSPEC: int - AF_VSOCK: int - AF_WANPIPE: int - AF_X25: int - -AF_UNIX: AddressFamily -AF_INET: AddressFamily -AF_INET6: AddressFamily -AF_AAL5: AddressFamily -AF_APPLETALK: AddressFamily -AF_ASH: AddressFamily -AF_ATMPVC: AddressFamily -AF_ATMSVC: AddressFamily -AF_AX25: AddressFamily -AF_BRIDGE: AddressFamily -AF_DECnet: AddressFamily -AF_ECONET: AddressFamily -AF_IPX: AddressFamily -AF_IRDA: AddressFamily -AF_KEY: AddressFamily -AF_LLC: AddressFamily -AF_NETBEUI: AddressFamily -AF_NETROM: AddressFamily -AF_PPPOX: AddressFamily -AF_ROSE: AddressFamily -AF_ROUTE: AddressFamily -AF_SECURITY: AddressFamily -AF_SNA: AddressFamily -AF_SYSTEM: AddressFamily -AF_UNSPEC: AddressFamily -AF_WANPIPE: AddressFamily -AF_X25: AddressFamily + if sys.platform != "darwin": + AF_IRDA: int + if sys.platform != "win32": + AF_ROUTE: int + AF_SYSTEM: int + AF_UNIX: int + if sys.platform != "darwin" and sys.platform != "win32": + AF_AAL5: int + AF_ASH: int + AF_ATMPVC: int + AF_ATMSVC: int + AF_AX25: int + AF_BRIDGE: int + AF_ECONET: int + AF_KEY: int + AF_LLC: int + AF_NETBEUI: int + AF_NETROM: int + AF_PPPOX: int + AF_ROSE: int + AF_SECURITY: int + AF_WANPIPE: int + AF_X25: int + if sys.platform == "linux": + AF_CAN: int + AF_PACKET: int + AF_RDS: int + AF_TIPC: int + AF_ALG: int + AF_NETLINK: int + if sys.version_info >= (3, 7): + AF_VSOCK: int + if sys.version_info >= (3, 8): + AF_QIPCRTR: int + if sys.platform != "win32" or sys.version_info >= (3, 9): + AF_LINK: int + if sys.platform != "darwin": + AF_BLUETOOTH: int + +AF_INET = AddressFamily.AF_INET +AF_INET6 = AddressFamily.AF_INET6 +AF_APPLETALK = AddressFamily.AF_APPLETALK +AF_DECnet = AddressFamily.AF_DECnet +AF_IPX = AddressFamily.AF_IPX +AF_SNA = AddressFamily.AF_SNA +AF_UNSPEC = AddressFamily.AF_UNSPEC + +if sys.platform != "darwin": + AF_IRDA = AddressFamily.AF_IRDA + +if sys.platform != "win32": + AF_ROUTE = AddressFamily.AF_ROUTE + AF_SYSTEM = AddressFamily.AF_SYSTEM + AF_UNIX = AddressFamily.AF_UNIX + +if sys.platform != "win32" and sys.platform != "darwin": + AF_AAL5 = AddressFamily.AF_AAL5 + AF_ASH = AddressFamily.AF_ASH + AF_ATMPVC = AddressFamily.AF_ATMPVC + AF_ATMSVC = AddressFamily.AF_ATMSVC + AF_AX25 = AddressFamily.AF_AX25 + AF_BRIDGE = AddressFamily.AF_BRIDGE + AF_ECONET = AddressFamily.AF_ECONET + AF_KEY = AddressFamily.AF_KEY + AF_LLC = AddressFamily.AF_LLC + AF_NETBEUI = AddressFamily.AF_NETBEUI + AF_NETROM = AddressFamily.AF_NETROM + AF_PPPOX = AddressFamily.AF_PPPOX + AF_ROSE = AddressFamily.AF_ROSE + AF_SECURITY = AddressFamily.AF_SECURITY + AF_WANPIPE = AddressFamily.AF_WANPIPE + AF_X25 = AddressFamily.AF_X25 + if sys.platform == "linux": - AF_CAN: AddressFamily - AF_PACKET: AddressFamily - AF_RDS: AddressFamily - AF_TIPC: AddressFamily - AF_ALG: AddressFamily - AF_NETLINK: AddressFamily + AF_CAN = AddressFamily.AF_CAN + AF_PACKET = AddressFamily.AF_PACKET + AF_RDS = AddressFamily.AF_RDS + AF_TIPC = AddressFamily.AF_TIPC + AF_ALG = AddressFamily.AF_ALG + AF_NETLINK = AddressFamily.AF_NETLINK if sys.version_info >= (3, 7): - AF_VSOCK: AddressFamily + AF_VSOCK = AddressFamily.AF_VSOCK if sys.version_info >= (3, 8): - AF_QIPCRTR: AddressFamily -AF_LINK: AddressFamily # availability: BSD, macOS -if sys.platform != "win32" and sys.platform != "darwin": - AF_BLUETOOTH: AddressFamily + AF_QIPCRTR = AddressFamily.AF_QIPCRTR + +if sys.platform != "win32" or sys.version_info >= (3, 9): + AF_LINK = AddressFamily.AF_LINK + if sys.platform != "darwin": + AF_BLUETOOTH = AddressFamily.AF_BLUETOOTH class SocketKind(IntEnum): SOCK_STREAM: int @@ -472,48 +539,77 @@ class SocketKind(IntEnum): SOCK_RAW: int SOCK_RDM: int SOCK_SEQPACKET: int - SOCK_CLOEXEC: int - SOCK_NONBLOCK: int - -SOCK_STREAM: SocketKind -SOCK_DGRAM: SocketKind -SOCK_RAW: SocketKind -SOCK_RDM: SocketKind -SOCK_SEQPACKET: SocketKind + if sys.platform == "linux": + SOCK_CLOEXEC: int + SOCK_NONBLOCK: int + +SOCK_STREAM = SocketKind.SOCK_STREAM +SOCK_DGRAM = SocketKind.SOCK_DGRAM +SOCK_RAW = SocketKind.SOCK_RAW +SOCK_RDM = SocketKind.SOCK_RDM +SOCK_SEQPACKET = SocketKind.SOCK_SEQPACKET if sys.platform == "linux": - SOCK_CLOEXEC: SocketKind - SOCK_NONBLOCK: SocketKind + SOCK_CLOEXEC = SocketKind.SOCK_CLOEXEC + SOCK_NONBLOCK = SocketKind.SOCK_NONBLOCK class MsgFlag(IntFlag): MSG_CTRUNC: int MSG_DONTROUTE: int - MSG_DONTWAIT: int - MSG_EOR: int MSG_OOB: int MSG_PEEK: int MSG_TRUNC: int MSG_WAITALL: int -MSG_BCAST: MsgFlag -MSG_BTAG: MsgFlag -MSG_CMSG_CLOEXEC: MsgFlag -MSG_CONFIRM: MsgFlag -MSG_CTRUNC: MsgFlag -MSG_DONTROUTE: MsgFlag -MSG_DONTWAIT: MsgFlag -MSG_EOF: MsgFlag -MSG_EOR: MsgFlag -MSG_ERRQUEUE: MsgFlag -MSG_ETAG: MsgFlag -MSG_FASTOPEN: MsgFlag -MSG_MCAST: MsgFlag -MSG_MORE: MsgFlag -MSG_NOSIGNAL: MsgFlag -MSG_NOTIFICATION: MsgFlag -MSG_OOB: MsgFlag -MSG_PEEK: MsgFlag -MSG_TRUNC: MsgFlag -MSG_WAITALL: MsgFlag + if sys.platform != "darwin": + MSG_BCAST: int + MSG_MCAST: int + + if sys.platform != "win32" or sys.version_info >= (3, 7): + MSG_ERRQUEUE: int + + if sys.platform != "win32" and sys.platform != "darwin": + MSG_BTAG: int + MSG_CMSG_CLOEXEC: int + MSG_CONFIRM: int + MSG_ETAG: int + MSG_FASTOPEN: int + MSG_MORE: int + MSG_NOTIFICATION: int + + if sys.platform != "win32": + MSG_DONTWAIT: int + MSG_EOF: int + MSG_EOR: int + MSG_NOSIGNAL: int # sometimes this exists on darwin, sometimes not + +MSG_CTRUNC = MsgFlag.MSG_CTRUNC +MSG_DONTROUTE = MsgFlag.MSG_DONTROUTE +MSG_OOB = MsgFlag.MSG_OOB +MSG_PEEK = MsgFlag.MSG_PEEK +MSG_TRUNC = MsgFlag.MSG_TRUNC +MSG_WAITALL = MsgFlag.MSG_WAITALL + +if sys.platform != "darwin": + MSG_BCAST = MsgFlag.MSG_BCAST + MSG_MCAST = MsgFlag.MSG_MCAST + + if sys.platform != "win32" or sys.version_info >= (3, 7): + MSG_ERRQUEUE = MsgFlag.MSG_ERRQUEUE + +if sys.platform != "win32": + MSG_DONTWAIT = MsgFlag.MSG_DONTWAIT + MSG_EOF = MsgFlag.MSG_EOF + MSG_EOR = MsgFlag.MSG_EOR + MSG_NOSIGNAL = MsgFlag.MSG_NOSIGNAL # Sometimes this exists on darwin, sometimes not + +if sys.platform != "win32" and sys.platform != "darwin": + MSG_BTAG = MsgFlag.MSG_BTAG + MSG_CMSG_CLOEXEC = MsgFlag.MSG_CMSG_CLOEXEC + MSG_CONFIRM = MsgFlag.MSG_CONFIRM + MSG_ETAG = MsgFlag.MSG_ETAG + MSG_FASTOPEN = MsgFlag.MSG_FASTOPEN + MSG_MORE = MsgFlag.MSG_MORE + MSG_NOTIFICATION = MsgFlag.MSG_NOTIFICATION class AddressInfo(IntFlag): AI_ADDRCONFIG: int @@ -523,17 +619,23 @@ class AddressInfo(IntFlag): AI_NUMERICSERV: int AI_PASSIVE: int AI_V4MAPPED: int + if sys.platform != "win32": + AI_DEFAULT: int + AI_MASK: int + AI_V4MAPPED_CFG: int -AI_ADDRCONFIG: AddressInfo -AI_ALL: AddressInfo -AI_CANONNAME: AddressInfo -AI_DEFAULT: AddressInfo -AI_MASK: AddressInfo -AI_NUMERICHOST: AddressInfo -AI_NUMERICSERV: AddressInfo -AI_PASSIVE: AddressInfo -AI_V4MAPPED: AddressInfo -AI_V4MAPPED_CFG: AddressInfo +AI_ADDRCONFIG = AddressInfo.AI_ADDRCONFIG +AI_ALL = AddressInfo.AI_ALL +AI_CANONNAME = AddressInfo.AI_CANONNAME +AI_NUMERICHOST = AddressInfo.AI_NUMERICHOST +AI_NUMERICSERV = AddressInfo.AI_NUMERICSERV +AI_PASSIVE = AddressInfo.AI_PASSIVE +AI_V4MAPPED = AddressInfo.AI_V4MAPPED + +if sys.platform != "win32": + AI_DEFAULT = AddressInfo.AI_DEFAULT + AI_MASK = AddressInfo.AI_MASK + AI_V4MAPPED_CFG = AddressInfo.AI_V4MAPPED_CFG if sys.platform == "win32": errorTab: dict[int, str] # undocumented diff --git a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi index 6db4a9294755..3e98908db354 100644 --- a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi +++ b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi @@ -341,7 +341,7 @@ class Connection: def set_authorizer( self, authorizer_callback: Callable[[int, str | None, str | None, str | None, str | None], int] | None ) -> None: ... - def set_progress_handler(self, progress_handler: Callable[[], bool | None] | None, n: int) -> None: ... + def set_progress_handler(self, progress_handler: Callable[[], int | None] | None, n: int) -> None: ... def set_trace_callback(self, trace_callback: Callable[[str], object] | None) -> None: ... # enable_load_extension and load_extension is not available on python distributions compiled # without sqlite3 loadable extension support. see footnotes https://docs.python.org/3/library/sqlite3.html#f1 diff --git a/mypy/typeshed/stdlib/subprocess.pyi b/mypy/typeshed/stdlib/subprocess.pyi index 6ce1073002b8..470069a96a80 100644 --- a/mypy/typeshed/stdlib/subprocess.pyi +++ b/mypy/typeshed/stdlib/subprocess.pyi @@ -95,20 +95,1209 @@ class CompletedProcess(Generic[_T]): # and writing all the overloads would be horrific. stdout: _T stderr: _T - def __init__(self, args: _CMD, returncode: int, stdout: _T | None = ..., stderr: _T | None = ...) -> None: ... + # type ignore on __init__ because the TypeVar can technically be unsolved, but see comment above + def __init__(self, args: _CMD, returncode: int, stdout: _T | None = ..., stderr: _T | None = ...) -> None: ... # type: ignore def check_returncode(self) -> None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... -if sys.version_info >= (3, 7): +if sys.version_info >= (3, 11): + # 3.11 adds "process_group" argument + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: Literal[True], + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str, + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str, + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: bytes | None = ..., + text: Literal[None, False] = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: _TXT | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> CompletedProcess[Any]: ... + +elif sys.version_info >= (3, 10): + # 3.10 adds "pipesize" argument + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: Literal[True], + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str, + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str, + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: bytes | None = ..., + text: Literal[None, False] = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: _TXT | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> CompletedProcess[Any]: ... + +elif sys.version_info >= (3, 9): + # 3.9 adds arguments "user", "group", "extra_groups" and "umask" + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: Literal[True], + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str, + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str, + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: bytes | None = ..., + text: Literal[None, False] = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: _TXT | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> CompletedProcess[Any]: ... + +elif sys.version_info >= (3, 7): # Nearly the same args as for 3.6, except for capture_output and text @overload - def run( + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: Literal[True], + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str, + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str, + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: bytes | None = ..., + text: Literal[None, False] = ..., + timeout: float | None = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + capture_output: bool = ..., + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: _TXT | None = ..., + text: bool | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[Any]: ... + +else: + # Nearly same args as Popen.__init__ except for timeout, input, and check + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: str, + errors: str | None = ..., + input: str | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: str | None = ..., + errors: str, + input: str | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the *real* keyword only args start + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: str | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[str]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: None = ..., + errors: None = ..., + input: bytes | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[bytes]: ... + @overload + def run( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + check: bool = ..., + encoding: str | None = ..., + errors: str | None = ..., + input: _TXT | None = ..., + timeout: float | None = ..., + ) -> CompletedProcess[Any]: ... + +# Same args as Popen.__init__ +if sys.version_info >= (3, 11): + # 3.11 adds "process_group" argument + def call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> int: ... + +elif sys.version_info >= (3, 10): + # 3.10 adds "pipesize" argument + def call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> int: ... + +elif sys.version_info >= (3, 9): + # 3.9 adds arguments "user", "group", "extra_groups" and "umask" + def call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> int: ... + +elif sys.version_info >= (3, 7): + # 3.7 adds the "text" argument + def call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + text: bool | None = ..., + ) -> int: ... + +else: + def call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + ) -> int: ... + +# Same args as Popen.__init__ +if sys.version_info >= (3, 11): + # 3.11 adds "process_group" argument + def check_call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float | None = ..., + *, + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> int: ... + +elif sys.version_info >= (3, 10): + # 3.10 adds "pipesize" argument + def check_call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float | None = ..., + *, + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> int: ... + +elif sys.version_info >= (3, 9): + # 3.9 adds arguments "user", "group", "extra_groups" and "umask" + def check_call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float | None = ..., + *, + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> int: ... + +elif sys.version_info >= (3, 7): + # 3.7 adds the "text" argument + def check_call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float | None = ..., + *, + text: bool | None = ..., + ) -> int: ... + +else: + def check_call( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float | None = ..., + ) -> int: ... + +if sys.version_info >= (3, 11): + # 3.11 adds "process_group" argument + @overload + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -122,21 +1311,24 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - capture_output: bool = ..., - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str | None = ..., - input: str | None = ..., text: Literal[True], - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -150,21 +1342,24 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - capture_output: bool = ..., - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str, errors: str | None = ..., - input: str | None = ..., text: bool | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -178,21 +1373,24 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - capture_output: bool = ..., - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str, - input: str | None = ..., text: bool | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -206,22 +1404,25 @@ if sys.version_info >= (3, 7): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - # where the *real* keyword only args start - capture_output: bool = ..., - check: bool = ..., + # where the real keyword only ones start + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str | None = ..., - input: str | None = ..., text: bool | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -235,21 +1436,24 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - capture_output: bool = ..., - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: None = ..., errors: None = ..., - input: bytes | None = ..., text: Literal[None, False] = ..., - timeout: float | None = ..., - ) -> CompletedProcess[bytes]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> bytes: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -263,24 +1467,27 @@ if sys.version_info >= (3, 7): start_new_session: bool = ..., pass_fds: Any = ..., *, - capture_output: bool = ..., - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str | None = ..., - input: _TXT | None = ..., text: bool | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[Any]: ... + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + process_group: int | None = ..., + ) -> Any: ... # morally: -> _TXT -else: - # Nearly same args as Popen.__init__ except for timeout, input, and check +elif sys.version_info >= (3, 10): + # 3.10 adds "pipesize" argument @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -294,19 +1501,53 @@ else: start_new_session: bool = ..., pass_fds: Any = ..., *, - check: bool = ..., - encoding: str, + timeout: float | None = ..., + input: _TXT | None = ..., + encoding: str | None = ..., errors: str | None = ..., - input: str | None = ..., + text: Literal[True], + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> str: ... + @overload + def check_output( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + input: _TXT | None = ..., + encoding: str, + errors: str | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -320,19 +1561,23 @@ else: start_new_session: bool = ..., pass_fds: Any = ..., *, - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str, - input: str | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -346,20 +1591,24 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., - # where the *real* keyword only args start - check: bool = ..., + # where the real keyword only ones start + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str | None = ..., - input: str | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[str]: ... + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> str: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -373,19 +1622,23 @@ else: start_new_session: bool = ..., pass_fds: Any = ..., *, - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: None = ..., errors: None = ..., - input: bytes | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[bytes]: ... + text: Literal[None, False] = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> bytes: ... @overload - def run( + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -399,21 +1652,26 @@ else: start_new_session: bool = ..., pass_fds: Any = ..., *, - check: bool = ..., + timeout: float | None = ..., + input: _TXT | None = ..., encoding: str | None = ..., errors: str | None = ..., - input: _TXT | None = ..., - timeout: float | None = ..., - ) -> CompletedProcess[Any]: ... + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + pipesize: int = ..., + ) -> Any: ... # morally: -> _TXT -# Same args as Popen.__init__ -if sys.version_info >= (3, 7): - def call( +elif sys.version_info >= (3, 9): + # 3.9 adds arguments "user", "group", "extra_groups" and "umask" + @overload + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -428,16 +1686,21 @@ if sys.version_info >= (3, 7): pass_fds: Any = ..., *, timeout: float | None = ..., - text: bool | None = ..., - ) -> int: ... - -else: - def call( + input: _TXT | None = ..., + encoding: str | None = ..., + errors: str | None = ..., + text: Literal[True], + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> str: ... + @overload + def check_output( args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -452,16 +1715,21 @@ else: pass_fds: Any = ..., *, timeout: float | None = ..., - ) -> int: ... - -# Same args as Popen.__init__ -if sys.version_info >= (3, 7): - def check_call( + input: _TXT | None = ..., + encoding: str, + errors: str | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> str: ... + @overload + def check_output( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -474,18 +1742,82 @@ if sys.version_info >= (3, 7): restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., + *, timeout: float | None = ..., + input: _TXT | None = ..., + encoding: str | None = ..., + errors: str, + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> str: ... + @overload + def check_output( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., *, + universal_newlines: Literal[True], + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + # where the real keyword only ones start + timeout: float | None = ..., + input: _TXT | None = ..., + encoding: str | None = ..., + errors: str | None = ..., text: bool | None = ..., - ) -> int: ... - -else: - def check_call( + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> str: ... + @overload + def check_output( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] | None = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: StrOrBytesPath | None = ..., + env: _ENV | None = ..., + universal_newlines: Literal[False] = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float | None = ..., + input: _TXT | None = ..., + encoding: None = ..., + errors: None = ..., + text: Literal[None, False] = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> bytes: ... + @overload + def check_output( + args: _CMD, + bufsize: int = ..., + executable: StrOrBytesPath | None = ..., stdin: _FILE = ..., - stdout: _FILE = ..., stderr: _FILE = ..., preexec_fn: Callable[[], Any] | None = ..., close_fds: bool = ..., @@ -498,10 +1830,19 @@ else: restore_signals: bool = ..., start_new_session: bool = ..., pass_fds: Any = ..., + *, timeout: float | None = ..., - ) -> int: ... + input: _TXT | None = ..., + encoding: str | None = ..., + errors: str | None = ..., + text: bool | None = ..., + user: str | int | None = ..., + group: str | int | None = ..., + extra_groups: Iterable[str | int] | None = ..., + umask: int = ..., + ) -> Any: ... # morally: -> _TXT -if sys.version_info >= (3, 7): +elif sys.version_info >= (3, 7): # 3.7 added text @overload def check_output( @@ -814,14 +2155,11 @@ class Popen(Generic[AnyStr]): returncode: int | Any universal_newlines: bool - # Technically it is wrong that Popen provides __new__ instead of __init__ - # but this shouldn't come up hopefully? - if sys.version_info >= (3, 11): # process_group is added in 3.11 @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -849,10 +2187,10 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -880,10 +2218,10 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -912,10 +2250,10 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -943,10 +2281,10 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[bytes], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -974,10 +2312,10 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[bytes]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[Any], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1005,12 +2343,12 @@ class Popen(Generic[AnyStr]): umask: int = ..., pipesize: int = ..., process_group: int | None = ..., - ) -> Popen[Any]: ... + ) -> None: ... elif sys.version_info >= (3, 10): # pipesize is added in 3.10 @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1037,10 +2375,10 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1067,10 +2405,10 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1098,10 +2436,10 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1128,10 +2466,10 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[bytes], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1158,10 +2496,10 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[bytes]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[Any], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1188,12 +2526,12 @@ class Popen(Generic[AnyStr]): extra_groups: Iterable[str | int] | None = ..., umask: int = ..., pipesize: int = ..., - ) -> Popen[Any]: ... + ) -> None: ... elif sys.version_info >= (3, 9): # user, group, extra_groups, umask were added in 3.9 @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1219,10 +2557,10 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1248,10 +2586,10 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1278,10 +2616,10 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1307,10 +2645,10 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[bytes], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1336,10 +2674,10 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[bytes]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[Any], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1365,12 +2703,12 @@ class Popen(Generic[AnyStr]): group: str | int | None = ..., extra_groups: Iterable[str | int] | None = ..., umask: int = ..., - ) -> Popen[Any]: ... + ) -> None: ... elif sys.version_info >= (3, 7): # text is added in 3.7 @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1392,10 +2730,10 @@ class Popen(Generic[AnyStr]): text: bool | None = ..., encoding: str, errors: str | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1417,10 +2755,10 @@ class Popen(Generic[AnyStr]): text: bool | None = ..., encoding: str | None = ..., errors: str, - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1443,10 +2781,10 @@ class Popen(Generic[AnyStr]): text: bool | None = ..., encoding: str | None = ..., errors: str | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1468,10 +2806,10 @@ class Popen(Generic[AnyStr]): text: Literal[True], encoding: str | None = ..., errors: str | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[bytes], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1493,10 +2831,10 @@ class Popen(Generic[AnyStr]): text: Literal[None, False] = ..., encoding: None = ..., errors: None = ..., - ) -> Popen[bytes]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[Any], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1518,11 +2856,11 @@ class Popen(Generic[AnyStr]): text: bool | None = ..., encoding: str | None = ..., errors: str | None = ..., - ) -> Popen[Any]: ... + ) -> None: ... else: @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1543,10 +2881,10 @@ class Popen(Generic[AnyStr]): *, encoding: str, errors: str | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1567,10 +2905,10 @@ class Popen(Generic[AnyStr]): *, encoding: str | None = ..., errors: str, - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[str], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1592,10 +2930,10 @@ class Popen(Generic[AnyStr]): # where the *real* keyword only args start encoding: str | None = ..., errors: str | None = ..., - ) -> Popen[str]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[bytes], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1616,10 +2954,10 @@ class Popen(Generic[AnyStr]): *, encoding: None = ..., errors: None = ..., - ) -> Popen[bytes]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: Popen[Any], args: _CMD, bufsize: int = ..., executable: StrOrBytesPath | None = ..., @@ -1640,7 +2978,7 @@ class Popen(Generic[AnyStr]): *, encoding: str | None = ..., errors: str | None = ..., - ) -> Popen[Any]: ... + ) -> None: ... def poll(self) -> int | None: ... if sys.version_info >= (3, 7): diff --git a/mypy/typeshed/stdlib/sys.pyi b/mypy/typeshed/stdlib/sys.pyi index 667b7024fe12..ef8dc085c7af 100644 --- a/mypy/typeshed/stdlib/sys.pyi +++ b/mypy/typeshed/stdlib/sys.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import OptExcInfo, structseq +from _typeshed import OptExcInfo, ProfileFunction, TraceFunction, structseq from builtins import object as _object from collections.abc import AsyncGenerator, Callable, Coroutine, Sequence from importlib.abc import PathEntryFinder @@ -75,7 +75,7 @@ _xoptions: dict[Any, Any] # Type alias used as a mixin for structseq classes that cannot be instantiated at runtime # This can't be represented in the type system, so we just use `structseq[Any]` -_uninstantiable_structseq: TypeAlias = structseq[Any] +_UninstantiableStructseq: TypeAlias = structseq[Any] flags: _flags @@ -87,7 +87,7 @@ else: _FlagTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int, int, int, int, int] @final -class _flags(_uninstantiable_structseq, _FlagTuple): +class _flags(_UninstantiableStructseq, _FlagTuple): @property def debug(self) -> int: ... @property @@ -198,7 +198,7 @@ class _int_info(structseq[int], tuple[int, int]): def sizeof_digit(self) -> int: ... @final -class _version_info(_uninstantiable_structseq, tuple[int, int, int, str, int]): +class _version_info(_UninstantiableStructseq, tuple[int, int, int, str, int]): @property def major(self) -> int: ... @property @@ -241,21 +241,15 @@ def getsizeof(obj: object) -> int: ... @overload def getsizeof(obj: object, default: int) -> int: ... def getswitchinterval() -> float: ... - -_ProfileFunc: TypeAlias = Callable[[FrameType, str, Any], Any] - -def getprofile() -> _ProfileFunc | None: ... -def setprofile(profilefunc: _ProfileFunc | None) -> None: ... - -_TraceFunc: TypeAlias = Callable[[FrameType, str, Any], Callable[[FrameType, str, Any], Any] | None] - -def gettrace() -> _TraceFunc | None: ... -def settrace(tracefunc: _TraceFunc | None) -> None: ... +def getprofile() -> ProfileFunction | None: ... +def setprofile(profilefunc: ProfileFunction | None) -> None: ... +def gettrace() -> TraceFunction | None: ... +def settrace(tracefunc: TraceFunction | None) -> None: ... if sys.platform == "win32": # A tuple of length 5, even though it has more than 5 attributes. @final - class _WinVersion(_uninstantiable_structseq, tuple[int, int, int, int, str]): + class _WinVersion(_UninstantiableStructseq, tuple[int, int, int, int, str]): @property def major(self) -> int: ... @property diff --git a/mypy/typeshed/stdlib/threading.pyi b/mypy/typeshed/stdlib/threading.pyi index afc37b771e8c..729def005831 100644 --- a/mypy/typeshed/stdlib/threading.pyi +++ b/mypy/typeshed/stdlib/threading.pyi @@ -1,13 +1,9 @@ import sys +from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping -from types import FrameType, TracebackType +from types import TracebackType from typing import Any, TypeVar -from typing_extensions import TypeAlias -# TODO recursive type -_TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None] - -_PF: TypeAlias = Callable[[FrameType, str, Any], None] _T = TypeVar("_T") __all__ = [ @@ -40,7 +36,7 @@ if sys.version_info >= (3, 8): if sys.version_info >= (3, 10): __all__ += ["getprofile", "gettrace"] -_profile_hook: _PF | None +_profile_hook: ProfileFunction | None def active_count() -> int: ... def activeCount() -> int: ... # deprecated alias for active_count() @@ -53,12 +49,12 @@ def main_thread() -> Thread: ... if sys.version_info >= (3, 8): from _thread import get_native_id as get_native_id -def settrace(func: _TF) -> None: ... -def setprofile(func: _PF | None) -> None: ... +def settrace(func: TraceFunction) -> None: ... +def setprofile(func: ProfileFunction | None) -> None: ... if sys.version_info >= (3, 10): - def gettrace() -> _TF | None: ... - def getprofile() -> _PF | None: ... + def gettrace() -> TraceFunction | None: ... + def getprofile() -> ProfileFunction | None: ... def stack_size(size: int = ...) -> int: ... diff --git a/mypy/typeshed/stdlib/trace.pyi b/mypy/typeshed/stdlib/trace.pyi index 3640cb11a878..1f0de1d4d964 100644 --- a/mypy/typeshed/stdlib/trace.pyi +++ b/mypy/typeshed/stdlib/trace.pyi @@ -1,6 +1,6 @@ import sys import types -from _typeshed import StrPath +from _typeshed import StrPath, TraceFunction from collections.abc import Callable, Mapping, Sequence from typing import Any, TypeVar from typing_extensions import ParamSpec, TypeAlias @@ -9,16 +9,15 @@ __all__ = ["Trace", "CoverageResults"] _T = TypeVar("_T") _P = ParamSpec("_P") -_localtrace: TypeAlias = Callable[[types.FrameType, str, Any], Callable[..., Any]] -_fileModuleFunction: TypeAlias = tuple[str, str | None, str] +_FileModuleFunction: TypeAlias = tuple[str, str | None, str] class CoverageResults: def __init__( self, counts: dict[tuple[str, int], int] | None = ..., - calledfuncs: dict[_fileModuleFunction, int] | None = ..., + calledfuncs: dict[_FileModuleFunction, int] | None = ..., infile: StrPath | None = ..., - callers: dict[tuple[_fileModuleFunction, _fileModuleFunction], int] | None = ..., + callers: dict[tuple[_FileModuleFunction, _FileModuleFunction], int] | None = ..., outfile: StrPath | None = ..., ) -> None: ... # undocumented def update(self, other: CoverageResults) -> None: ... @@ -50,11 +49,11 @@ class Trace: else: def runfunc(self, func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ... - def file_module_function_of(self, frame: types.FrameType) -> _fileModuleFunction: ... + def file_module_function_of(self, frame: types.FrameType) -> _FileModuleFunction: ... def globaltrace_trackcallers(self, frame: types.FrameType, why: str, arg: Any) -> None: ... def globaltrace_countfuncs(self, frame: types.FrameType, why: str, arg: Any) -> None: ... def globaltrace_lt(self, frame: types.FrameType, why: str, arg: Any) -> None: ... - def localtrace_trace_and_count(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... - def localtrace_trace(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... - def localtrace_count(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... + def localtrace_trace_and_count(self, frame: types.FrameType, why: str, arg: Any) -> TraceFunction: ... + def localtrace_trace(self, frame: types.FrameType, why: str, arg: Any) -> TraceFunction: ... + def localtrace_count(self, frame: types.FrameType, why: str, arg: Any) -> TraceFunction: ... def results(self) -> CoverageResults: ... diff --git a/mypy/typeshed/stdlib/traceback.pyi b/mypy/typeshed/stdlib/traceback.pyi index 16151f9431eb..dbbcc824a04c 100644 --- a/mypy/typeshed/stdlib/traceback.pyi +++ b/mypy/typeshed/stdlib/traceback.pyi @@ -252,7 +252,7 @@ class StackSummary(list[FrameSummary]): capture_locals: bool = ..., ) -> StackSummary: ... @classmethod - def from_list(cls, a_list: list[_PT]) -> StackSummary: ... + def from_list(cls, a_list: Iterable[FrameSummary | _PT]) -> StackSummary: ... if sys.version_info >= (3, 11): def format_frame_summary(self, frame_summary: FrameSummary) -> str: ... diff --git a/mypy/typeshed/stdlib/tracemalloc.pyi b/mypy/typeshed/stdlib/tracemalloc.pyi index 193a4acc7c2d..4b7063e5d800 100644 --- a/mypy/typeshed/stdlib/tracemalloc.pyi +++ b/mypy/typeshed/stdlib/tracemalloc.pyi @@ -42,14 +42,14 @@ class StatisticDiff: def __init__(self, traceback: Traceback, size: int, size_diff: int, count: int, count_diff: int) -> None: ... def __eq__(self, other: object) -> bool: ... -_FrameTupleT: TypeAlias = tuple[str, int] +_FrameTuple: TypeAlias = tuple[str, int] class Frame: @property def filename(self) -> str: ... @property def lineno(self) -> int: ... - def __init__(self, frame: _FrameTupleT) -> None: ... + def __init__(self, frame: _FrameTuple) -> None: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: Frame) -> bool: ... if sys.version_info >= (3, 11): @@ -62,9 +62,9 @@ class Frame: def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... if sys.version_info >= (3, 9): - _TraceTupleT: TypeAlias = Union[tuple[int, int, Sequence[_FrameTupleT], int | None], tuple[int, int, Sequence[_FrameTupleT]]] + _TraceTuple: TypeAlias = Union[tuple[int, int, Sequence[_FrameTuple], int | None], tuple[int, int, Sequence[_FrameTuple]]] else: - _TraceTupleT: TypeAlias = tuple[int, int, Sequence[_FrameTupleT]] + _TraceTuple: TypeAlias = tuple[int, int, Sequence[_FrameTuple]] class Trace: @property @@ -73,16 +73,16 @@ class Trace: def size(self) -> int: ... @property def traceback(self) -> Traceback: ... - def __init__(self, trace: _TraceTupleT) -> None: ... + def __init__(self, trace: _TraceTuple) -> None: ... def __eq__(self, other: object) -> bool: ... class Traceback(Sequence[Frame]): if sys.version_info >= (3, 9): @property def total_nframe(self) -> int | None: ... - def __init__(self, frames: Sequence[_FrameTupleT], total_nframe: int | None = ...) -> None: ... + def __init__(self, frames: Sequence[_FrameTuple], total_nframe: int | None = ...) -> None: ... else: - def __init__(self, frames: Sequence[_FrameTupleT]) -> None: ... + def __init__(self, frames: Sequence[_FrameTuple]) -> None: ... if sys.version_info >= (3, 7): def format(self, limit: int | None = ..., most_recent_first: bool = ...) -> list[str]: ... else: @@ -106,7 +106,7 @@ class Traceback(Sequence[Frame]): def __le__(self, other: Traceback, NotImplemented: Any = ...) -> bool: ... class Snapshot: - def __init__(self, traces: Sequence[_TraceTupleT], traceback_limit: int) -> None: ... + def __init__(self, traces: Sequence[_TraceTuple], traceback_limit: int) -> None: ... def compare_to(self, old_snapshot: Snapshot, key_type: str, cumulative: bool = ...) -> list[StatisticDiff]: ... def dump(self, filename: str) -> None: ... def filter_traces(self, filters: Sequence[DomainFilter | Filter]) -> Snapshot: ... diff --git a/mypy/typeshed/stdlib/turtle.pyi b/mypy/typeshed/stdlib/turtle.pyi index cdacaf63c41f..13197c336e5e 100644 --- a/mypy/typeshed/stdlib/turtle.pyi +++ b/mypy/typeshed/stdlib/turtle.pyi @@ -221,10 +221,10 @@ class TurtleScreen(TurtleScreenBase): def window_height(self) -> int: ... def getcanvas(self) -> Canvas: ... def getshapes(self) -> list[str]: ... - def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ... - def onkey(self, fun: Callable[[], Any], key: str) -> None: ... + def onclick(self, fun: Callable[[float, float], object], btn: int = ..., add: Any | None = ...) -> None: ... + def onkey(self, fun: Callable[[], object], key: str) -> None: ... def listen(self, xdummy: float | None = ..., ydummy: float | None = ...) -> None: ... - def ontimer(self, fun: Callable[[], Any], t: int = ...) -> None: ... + def ontimer(self, fun: Callable[[], object], t: int = ...) -> None: ... @overload def bgpic(self, picname: None = ...) -> str: ... @overload @@ -238,7 +238,7 @@ class TurtleScreen(TurtleScreenBase): resetscreen = reset clearscreen = clear addshape = register_shape - def onkeypress(self, fun: Callable[[], Any], key: str | None = ...) -> None: ... + def onkeypress(self, fun: Callable[[], object], key: str | None = ...) -> None: ... onkeyrelease = onkey class TNavigator: @@ -409,9 +409,9 @@ class RawTurtle(TPen, TNavigator): def getscreen(self) -> TurtleScreen: ... def getturtle(self: Self) -> Self: ... getpen = getturtle - def onclick(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ... - def onrelease(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ... - def ondrag(self, fun: Callable[[float, float], Any], btn: int = ..., add: bool | None = ...) -> None: ... + def onclick(self, fun: Callable[[float, float], object], btn: int = ..., add: bool | None = ...) -> None: ... + def onrelease(self, fun: Callable[[float, float], object], btn: int = ..., add: bool | None = ...) -> None: ... + def ondrag(self, fun: Callable[[float, float], object], btn: int = ..., add: bool | None = ...) -> None: ... def undo(self) -> None: ... turtlesize = shapesize @@ -490,10 +490,10 @@ def window_width() -> int: ... def window_height() -> int: ... def getcanvas() -> Canvas: ... def getshapes() -> list[str]: ... -def onclick(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ... -def onkey(fun: Callable[[], Any], key: str) -> None: ... +def onclick(fun: Callable[[float, float], object], btn: int = ..., add: Any | None = ...) -> None: ... +def onkey(fun: Callable[[], object], key: str) -> None: ... def listen(xdummy: float | None = ..., ydummy: float | None = ...) -> None: ... -def ontimer(fun: Callable[[], Any], t: int = ...) -> None: ... +def ontimer(fun: Callable[[], object], t: int = ...) -> None: ... @overload def bgpic(picname: None = ...) -> str: ... @overload @@ -508,7 +508,7 @@ resetscreen = reset clearscreen = clear addshape = register_shape -def onkeypress(fun: Callable[[], Any], key: str | None = ...) -> None: ... +def onkeypress(fun: Callable[[], object], key: str | None = ...) -> None: ... onkeyrelease = onkey @@ -680,8 +680,8 @@ def getturtle() -> Turtle: ... getpen = getturtle -def onrelease(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ... -def ondrag(fun: Callable[[float, float], Any], btn: int = ..., add: Any | None = ...) -> None: ... +def onrelease(fun: Callable[[float, float], object], btn: int = ..., add: Any | None = ...) -> None: ... +def ondrag(fun: Callable[[float, float], object], btn: int = ..., add: Any | None = ...) -> None: ... def undo() -> None: ... turtlesize = shapesize diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index de8c8423d47e..ecd42dbe3ba3 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -583,7 +583,7 @@ if sys.version_info >= (3, 7): name: str, bases: Iterable[object] = ..., kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], None] | None = ..., + exec_body: Callable[[dict[str, Any]], object] | None = ..., ) -> type: ... def resolve_bases(bases: Iterable[object]) -> tuple[Any, ...]: ... @@ -592,7 +592,7 @@ else: name: str, bases: tuple[type, ...] = ..., kwds: dict[str, Any] | None = ..., - exec_body: Callable[[dict[str, Any]], None] | None = ..., + exec_body: Callable[[dict[str, Any]], object] | None = ..., ) -> type: ... def prepare_class( diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 969e61952d5f..acbce5cd3a5f 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -115,6 +115,9 @@ if sys.version_info >= (3, 11): "reveal_type", ] +# This itself is only available during type checking +def type_check_only(func_or_cls: _F) -> _F: ... + Any = object() @_final @@ -391,6 +394,7 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): # NOTE: This type does not exist in typing.py or PEP 484 but mypy needs it to exist. # The parameters correspond to Generator, but the 4th is the original type. +@type_check_only class AwaitableGenerator( Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta ): ... @@ -915,9 +919,6 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... -# This itself is only available during type checking -def type_check_only(func_or_cls: _F) -> _F: ... - if sys.version_info >= (3, 7): @_final class ForwardRef: diff --git a/mypy/typeshed/stdlib/typing_extensions.pyi b/mypy/typeshed/stdlib/typing_extensions.pyi index 38fb9dec19d9..fab5900128a5 100644 --- a/mypy/typeshed/stdlib/typing_extensions.pyi +++ b/mypy/typeshed/stdlib/typing_extensions.pyi @@ -37,6 +37,8 @@ __all__ = [ "Final", "LiteralString", "ParamSpec", + "ParamSpecArgs", + "ParamSpecKwargs", "Self", "Type", "TypeVarTuple", @@ -158,6 +160,8 @@ if sys.version_info >= (3, 10): from typing import ( Concatenate as Concatenate, ParamSpec as ParamSpec, + ParamSpecArgs as ParamSpecArgs, + ParamSpecKwargs as ParamSpecKwargs, TypeAlias as TypeAlias, TypeGuard as TypeGuard, is_typeddict as is_typeddict, diff --git a/mypy/typeshed/stdlib/unittest/case.pyi b/mypy/typeshed/stdlib/unittest/case.pyi index 4f69c0a1f3b8..8892d4a5efcb 100644 --- a/mypy/typeshed/stdlib/unittest/case.pyi +++ b/mypy/typeshed/stdlib/unittest/case.pyi @@ -1,7 +1,7 @@ import logging import sys import unittest.result -from _typeshed import Self, SupportsDunderGE, SupportsRSub, SupportsSub +from _typeshed import Self, SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet from contextlib import AbstractContextManager from types import TracebackType @@ -17,14 +17,18 @@ from typing import ( SupportsAbs, SupportsRound, TypeVar, + Union, overload, ) -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, TypeAlias from warnings import WarningMessage if sys.version_info >= (3, 9): from types import GenericAlias +if sys.version_info >= (3, 10): + from types import UnionType + _T = TypeVar("_T") _S = TypeVar("_S", bound=SupportsSub[Any, Any]) _E = TypeVar("_E", bound=BaseException) @@ -75,7 +79,12 @@ def skipUnless(condition: object, reason: str) -> Callable[[_FT], _FT]: ... class SkipTest(Exception): def __init__(self, reason: str) -> None: ... -class _SupportsAbsAndDunderGE(SupportsDunderGE, SupportsAbs[Any], Protocol): ... +class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ... + +if sys.version_info >= (3, 10): + _IsInstanceClassInfo: TypeAlias = Union[type, UnionType, tuple[type | UnionType | tuple[Any, ...], ...]] +else: + _IsInstanceClassInfo: TypeAlias = Union[type, tuple[type | tuple[Any, ...], ...]] class TestCase: failureException: type[BaseException] @@ -105,18 +114,30 @@ class TestCase: def assertNotEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ... def assertTrue(self, expr: Any, msg: Any = ...) -> None: ... def assertFalse(self, expr: Any, msg: Any = ...) -> None: ... - def assertIs(self, expr1: Any, expr2: Any, msg: Any = ...) -> None: ... - def assertIsNot(self, expr1: Any, expr2: Any, msg: Any = ...) -> None: ... - def assertIsNone(self, obj: Any, msg: Any = ...) -> None: ... - def assertIsNotNone(self, obj: Any, msg: Any = ...) -> None: ... + def assertIs(self, expr1: object, expr2: object, msg: Any = ...) -> None: ... + def assertIsNot(self, expr1: object, expr2: object, msg: Any = ...) -> None: ... + def assertIsNone(self, obj: object, msg: Any = ...) -> None: ... + def assertIsNotNone(self, obj: object, msg: Any = ...) -> None: ... def assertIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = ...) -> None: ... def assertNotIn(self, member: Any, container: Iterable[Any] | Container[Any], msg: Any = ...) -> None: ... - def assertIsInstance(self, obj: Any, cls: type | tuple[type, ...], msg: Any = ...) -> None: ... - def assertNotIsInstance(self, obj: Any, cls: type | tuple[type, ...], msg: Any = ...) -> None: ... - def assertGreater(self, a: Any, b: Any, msg: Any = ...) -> None: ... - def assertGreaterEqual(self, a: Any, b: Any, msg: Any = ...) -> None: ... - def assertLess(self, a: Any, b: Any, msg: Any = ...) -> None: ... - def assertLessEqual(self, a: Any, b: Any, msg: Any = ...) -> None: ... + def assertIsInstance(self, obj: object, cls: _IsInstanceClassInfo, msg: Any = ...) -> None: ... + def assertNotIsInstance(self, obj: object, cls: _IsInstanceClassInfo, msg: Any = ...) -> None: ... + @overload + def assertGreater(self, a: SupportsDunderGT[_T], b: _T, msg: Any = ...) -> None: ... + @overload + def assertGreater(self, a: _T, b: SupportsDunderLT[_T], msg: Any = ...) -> None: ... + @overload + def assertGreaterEqual(self, a: SupportsDunderGE[_T], b: _T, msg: Any = ...) -> None: ... + @overload + def assertGreaterEqual(self, a: _T, b: SupportsDunderLE[_T], msg: Any = ...) -> None: ... + @overload + def assertLess(self, a: SupportsDunderLT[_T], b: _T, msg: Any = ...) -> None: ... + @overload + def assertLess(self, a: _T, b: SupportsDunderGT[_T], msg: Any = ...) -> None: ... + @overload + def assertLessEqual(self, a: SupportsDunderLT[_T], b: _T, msg: Any = ...) -> None: ... + @overload + def assertLessEqual(self, a: _T, b: SupportsDunderGT[_T], msg: Any = ...) -> None: ... # `assertRaises`, `assertRaisesRegex`, and `assertRaisesRegexp` # are not using `ParamSpec` intentionally, # because they might be used with explicitly wrong arg types to raise some error in tests. @@ -267,45 +288,21 @@ class TestCase: def _formatMessage(self, msg: str | None, standardMsg: str) -> str: ... # undocumented def _getAssertEqualityFunc(self, first: Any, second: Any) -> Callable[..., None]: ... # undocumented if sys.version_info < (3, 12): - def failUnlessEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ... - def assertEquals(self, first: Any, second: Any, msg: Any = ...) -> None: ... - def failIfEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ... - def assertNotEquals(self, first: Any, second: Any, msg: Any = ...) -> None: ... - def failUnless(self, expr: bool, msg: Any = ...) -> None: ... - def assert_(self, expr: bool, msg: Any = ...) -> None: ... - def failIf(self, expr: bool, msg: Any = ...) -> None: ... - @overload - def failUnlessRaises( # type: ignore[misc] - self, - exception: type[BaseException] | tuple[type[BaseException], ...], - callable: Callable[_P, object] = ..., - *args: _P.args, - **kwargs: _P.kwargs, - ) -> None: ... - @overload - def failUnlessRaises(self, exception: type[_E] | tuple[type[_E], ...], msg: Any = ...) -> _AssertRaisesContext[_E]: ... + failUnlessEqual = assertEqual + assertEquals = assertEqual + failIfEqual = assertNotEqual + assertNotEquals = assertNotEqual + failUnless = assertTrue + assert_ = assertTrue + failIf = assertFalse + failUnlessRaises = assertRaises failUnlessAlmostEqual = assertAlmostEqual assertAlmostEquals = assertAlmostEqual failIfAlmostEqual = assertNotAlmostEqual assertNotAlmostEquals = assertNotAlmostEqual - def assertRegexpMatches(self, text: AnyStr, regex: AnyStr | Pattern[AnyStr], msg: Any = ...) -> None: ... - def assertNotRegexpMatches(self, text: AnyStr, regex: AnyStr | Pattern[AnyStr], msg: Any = ...) -> None: ... - @overload - def assertRaisesRegexp( # type: ignore[misc] - self, - exception: type[BaseException] | tuple[type[BaseException], ...], - expected_regex: str | bytes | Pattern[str] | Pattern[bytes], - callable: Callable[..., object], - *args: Any, - **kwargs: Any, - ) -> None: ... - @overload - def assertRaisesRegexp( - self, - exception: type[_E] | tuple[type[_E], ...], - expected_regex: str | bytes | Pattern[str] | Pattern[bytes], - msg: Any = ..., - ) -> _AssertRaisesContext[_E]: ... + assertRegexpMatches = assertRegex + assertNotRegexpMatches = assertNotRegex + assertRaisesRegexp = assertRaisesRegex def assertDictContainsSubset( self, subset: Mapping[Any, Any], dictionary: Mapping[Any, Any], msg: object = ... ) -> None: ... @@ -313,9 +310,9 @@ class TestCase: class FunctionTestCase(TestCase): def __init__( self, - testFunc: Callable[[], None], - setUp: Callable[[], None] | None = ..., - tearDown: Callable[[], None] | None = ..., + testFunc: Callable[[], object], + setUp: Callable[[], object] | None = ..., + tearDown: Callable[[], object] | None = ..., description: str | None = ..., ) -> None: ... def runTest(self) -> None: ... diff --git a/mypy/typeshed/stdlib/unittest/mock.pyi b/mypy/typeshed/stdlib/unittest/mock.pyi index a7111ff2d090..d4e9e832c929 100644 --- a/mypy/typeshed/stdlib/unittest/mock.pyi +++ b/mypy/typeshed/stdlib/unittest/mock.pyi @@ -65,8 +65,6 @@ __version__: str FILTER_DIR: Any -class _slotted: ... - class _SentinelObject: name: Any def __init__(self, name: Any) -> None: ... diff --git a/mypy/typeshed/stdlib/urllib/request.pyi b/mypy/typeshed/stdlib/urllib/request.pyi index 02ad1bd30052..c44e5cf7043c 100644 --- a/mypy/typeshed/stdlib/urllib/request.pyi +++ b/mypy/typeshed/stdlib/urllib/request.pyi @@ -7,7 +7,7 @@ from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol from http.cookiejar import CookieJar from typing import IO, Any, ClassVar, NoReturn, Pattern, TypeVar, overload from typing_extensions import TypeAlias -from urllib.error import HTTPError +from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl __all__ = [ @@ -285,7 +285,7 @@ class HTTPErrorProcessor(BaseHandler): def urlretrieve( url: str, filename: StrOrBytesPath | None = ..., - reporthook: Callable[[int, int, int], None] | None = ..., + reporthook: Callable[[int, int, int], object] | None = ..., data: _DataType = ..., ) -> tuple[str, HTTPMessage]: ... def urlcleanup() -> None: ... @@ -299,7 +299,7 @@ class URLopener: self, url: str, filename: str | None = ..., - reporthook: Callable[[int, int, int], None] | None = ..., + reporthook: Callable[[int, int, int], object] | None = ..., data: bytes | None = ..., ) -> tuple[str, Message | None]: ... def addheader(self, *args: tuple[str, str]) -> None: ... # undocumented diff --git a/mypy/typeshed/stdlib/warnings.pyi b/mypy/typeshed/stdlib/warnings.pyi index c9c143991e3a..5cc6b946409b 100644 --- a/mypy/typeshed/stdlib/warnings.pyi +++ b/mypy/typeshed/stdlib/warnings.pyi @@ -2,7 +2,7 @@ import sys from _warnings import warn as warn, warn_explicit as warn_explicit from collections.abc import Sequence from types import ModuleType, TracebackType -from typing import Any, TextIO, overload +from typing import Any, Generic, TextIO, TypeVar, overload from typing_extensions import Literal, TypeAlias __all__ = [ @@ -16,6 +16,7 @@ __all__ = [ "catch_warnings", ] +_W = TypeVar("_W", bound=list[WarningMessage] | None) _ActionKind: TypeAlias = Literal["default", "error", "ignore", "always", "module", "once"] filters: Sequence[tuple[str, str | None, type[Warning], str | None, int]] # undocumented, do not mutate @@ -56,11 +57,11 @@ class WarningMessage: source: Any | None = ..., ) -> None: ... -class catch_warnings: +class catch_warnings(Generic[_W]): if sys.version_info >= (3, 11): @overload - def __new__( - cls, + def __init__( + self: catch_warnings[None], *, record: Literal[False] = ..., module: ModuleType | None = ..., @@ -68,10 +69,10 @@ class catch_warnings: category: type[Warning] = ..., lineno: int = ..., append: bool = ..., - ) -> _catch_warnings_without_records: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: catch_warnings[list[WarningMessage]], *, record: Literal[True], module: ModuleType | None = ..., @@ -79,10 +80,10 @@ class catch_warnings: category: type[Warning] = ..., lineno: int = ..., append: bool = ..., - ) -> _catch_warnings_with_records: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: catch_warnings[list[WarningMessage] | None], *, record: bool, module: ModuleType | None = ..., @@ -90,22 +91,20 @@ class catch_warnings: category: type[Warning] = ..., lineno: int = ..., append: bool = ..., - ) -> catch_warnings: ... + ) -> None: ... else: @overload - def __new__(cls, *, record: Literal[False] = ..., module: ModuleType | None = ...) -> _catch_warnings_without_records: ... + def __init__(self: catch_warnings[None], *, record: Literal[False] = ..., module: ModuleType | None = ...) -> None: ... @overload - def __new__(cls, *, record: Literal[True], module: ModuleType | None = ...) -> _catch_warnings_with_records: ... + def __init__( + self: catch_warnings[list[WarningMessage]], *, record: Literal[True], module: ModuleType | None = ... + ) -> None: ... @overload - def __new__(cls, *, record: bool, module: ModuleType | None = ...) -> catch_warnings: ... + def __init__( + self: catch_warnings[list[WarningMessage] | None], *, record: bool, module: ModuleType | None = ... + ) -> None: ... - def __enter__(self) -> list[WarningMessage] | None: ... + def __enter__(self) -> _W: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... - -class _catch_warnings_without_records(catch_warnings): - def __enter__(self) -> None: ... - -class _catch_warnings_with_records(catch_warnings): - def __enter__(self) -> list[WarningMessage]: ... diff --git a/mypy/typeshed/stdlib/xdrlib.pyi b/mypy/typeshed/stdlib/xdrlib.pyi index e6b78d5542be..e0b8c6a54b00 100644 --- a/mypy/typeshed/stdlib/xdrlib.pyi +++ b/mypy/typeshed/stdlib/xdrlib.pyi @@ -29,9 +29,9 @@ class Packer: def pack_string(self, s: bytes) -> None: ... def pack_opaque(self, s: bytes) -> None: ... def pack_bytes(self, s: bytes) -> None: ... - def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... - def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... - def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... + def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... + def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... + def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], object]) -> None: ... class Unpacker: def __init__(self, data: bytes) -> None: ... diff --git a/mypy/typeshed/stdlib/xml/etree/ElementPath.pyi b/mypy/typeshed/stdlib/xml/etree/ElementPath.pyi index e5b8223aab34..1f652050e4fd 100644 --- a/mypy/typeshed/stdlib/xml/etree/ElementPath.pyi +++ b/mypy/typeshed/stdlib/xml/etree/ElementPath.pyi @@ -6,19 +6,19 @@ from xml.etree.ElementTree import Element xpath_tokenizer_re: Pattern[str] _token: TypeAlias = tuple[str, str] -_next: TypeAlias = Callable[[], _token] -_callback: TypeAlias = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]] +_Next: TypeAlias = Callable[[], _token] +_Callback: TypeAlias = Callable[[_SelectorContext, list[Element]], Generator[Element, None, None]] def xpath_tokenizer(pattern: str, namespaces: dict[str, str] | None = ...) -> Generator[_token, None, None]: ... def get_parent_map(context: _SelectorContext) -> dict[Element, Element]: ... -def prepare_child(next: _next, token: _token) -> _callback: ... -def prepare_star(next: _next, token: _token) -> _callback: ... -def prepare_self(next: _next, token: _token) -> _callback: ... -def prepare_descendant(next: _next, token: _token) -> _callback: ... -def prepare_parent(next: _next, token: _token) -> _callback: ... -def prepare_predicate(next: _next, token: _token) -> _callback: ... +def prepare_child(next: _Next, token: _token) -> _Callback: ... +def prepare_star(next: _Next, token: _token) -> _Callback: ... +def prepare_self(next: _Next, token: _token) -> _Callback: ... +def prepare_descendant(next: _Next, token: _token) -> _Callback: ... +def prepare_parent(next: _Next, token: _token) -> _Callback: ... +def prepare_predicate(next: _Next, token: _token) -> _Callback: ... -ops: dict[str, Callable[[_next, _token], _callback]] +ops: dict[str, Callable[[_Next, _token], _Callback]] class _SelectorContext: parent_map: dict[Element, Element] | None diff --git a/mypy/typeshed/stdlib/xml/sax/__init__.pyi b/mypy/typeshed/stdlib/xml/sax/__init__.pyi index 22a2764a699f..af4ee052480f 100644 --- a/mypy/typeshed/stdlib/xml/sax/__init__.pyi +++ b/mypy/typeshed/stdlib/xml/sax/__init__.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsRead, _T_co from collections.abc import Iterable from typing import Any, NoReturn, Protocol -from xml.sax.handler import ContentHandler, ErrorHandler +from xml.sax.handler import ContentHandler as ContentHandler, ErrorHandler as ErrorHandler from xml.sax.xmlreader import Locator, XMLReader class _SupportsReadClose(SupportsRead[_T_co], Protocol[_T_co]): diff --git a/mypy/typeshed/stdlib/xmlrpc/client.pyi b/mypy/typeshed/stdlib/xmlrpc/client.pyi index d4e82d5e40da..7c0ba5c62fd7 100644 --- a/mypy/typeshed/stdlib/xmlrpc/client.pyi +++ b/mypy/typeshed/stdlib/xmlrpc/client.pyi @@ -97,32 +97,31 @@ class ExpatParser: # undocumented def feed(self, data: str | bytes) -> None: ... def close(self) -> None: ... -class Marshaller: - - dispatch: dict[ - type[Any], Callable[[Marshaller, Any, Callable[[str], Any]], None] - ] # TODO: Replace 'Any' with some kind of binding +_WriteCallback: TypeAlias = Callable[[str], object] +class Marshaller: + # TODO: Replace 'Any' with some kind of binding + dispatch: dict[type[Any], Callable[[Marshaller, Any, _WriteCallback], None]] memo: dict[Any, None] data: None encoding: str | None allow_none: bool def __init__(self, encoding: str | None = ..., allow_none: bool = ...) -> None: ... def dumps(self, values: Fault | Iterable[_Marshallable]) -> str: ... - def __dump(self, value: _Marshallable, write: Callable[[str], Any]) -> None: ... # undocumented - def dump_nil(self, value: None, write: Callable[[str], Any]) -> None: ... - def dump_bool(self, value: bool, write: Callable[[str], Any]) -> None: ... - def dump_long(self, value: int, write: Callable[[str], Any]) -> None: ... - def dump_int(self, value: int, write: Callable[[str], Any]) -> None: ... - def dump_double(self, value: float, write: Callable[[str], Any]) -> None: ... - def dump_unicode(self, value: str, write: Callable[[str], Any], escape: Callable[[str], str] = ...) -> None: ... - def dump_bytes(self, value: bytes, write: Callable[[str], Any]) -> None: ... - def dump_array(self, value: Iterable[_Marshallable], write: Callable[[str], Any]) -> None: ... + def __dump(self, value: _Marshallable, write: _WriteCallback) -> None: ... # undocumented + def dump_nil(self, value: None, write: _WriteCallback) -> None: ... + def dump_bool(self, value: bool, write: _WriteCallback) -> None: ... + def dump_long(self, value: int, write: _WriteCallback) -> None: ... + def dump_int(self, value: int, write: _WriteCallback) -> None: ... + def dump_double(self, value: float, write: _WriteCallback) -> None: ... + def dump_unicode(self, value: str, write: _WriteCallback, escape: Callable[[str], str] = ...) -> None: ... + def dump_bytes(self, value: bytes, write: _WriteCallback) -> None: ... + def dump_array(self, value: Iterable[_Marshallable], write: _WriteCallback) -> None: ... def dump_struct( - self, value: Mapping[str, _Marshallable], write: Callable[[str], Any], escape: Callable[[str], str] = ... + self, value: Mapping[str, _Marshallable], write: _WriteCallback, escape: Callable[[str], str] = ... ) -> None: ... - def dump_datetime(self, value: _XMLDate, write: Callable[[str], Any]) -> None: ... - def dump_instance(self, value: object, write: Callable[[str], Any]) -> None: ... + def dump_datetime(self, value: _XMLDate, write: _WriteCallback) -> None: ... + def dump_instance(self, value: object, write: _WriteCallback) -> None: ... class Unmarshaller: diff --git a/mypy/typeshed/stubs/mypy-extensions/METADATA.toml b/mypy/typeshed/stubs/mypy-extensions/METADATA.toml index 582104d3a1a7..de6579f75d05 100644 --- a/mypy/typeshed/stubs/mypy-extensions/METADATA.toml +++ b/mypy/typeshed/stubs/mypy-extensions/METADATA.toml @@ -1 +1,4 @@ version = "0.4.*" + +[tool.stubtest] +ignore_missing_stub = false