Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync typeshed #15590

Merged
merged 5 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_collections_abc.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from abc import abstractmethod
from types import MappingProxyType
from typing import ( # noqa: Y022,Y038
from typing import ( # noqa: Y022,Y038,Y057
AbstractSet as Set,
AsyncGenerator as AsyncGenerator,
AsyncIterable as AsyncIterable,
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ _T = TypeVar("_T")

# Aliases imported by multiple submodules in typeshed
if sys.version_info >= (3, 12):
_AwaitableLike: TypeAlias = Awaitable[_T]
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T]
_AwaitableLike: TypeAlias = Awaitable[_T] # noqa: Y047
_CoroutineLike: TypeAlias = Coroutine[Any, Any, _T] # noqa: Y047
else:
_AwaitableLike: TypeAlias = Generator[Any, None, _T] | Awaitable[_T]
_CoroutineLike: TypeAlias = Generator[Any, None, _T] | Coroutine[Any, Any, _T]
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class BaseEventLoop(AbstractEventLoop):
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
Expand Down Expand Up @@ -317,7 +317,7 @@ class BaseEventLoop(AbstractEventLoop):
server_side: bool = False,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class AbstractEventLoop:
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
Expand Down Expand Up @@ -418,7 +418,7 @@ class AbstractEventLoop:
server_side: bool = False,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
) -> Transport: ...
) -> Transport | None: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
Expand Down
6 changes: 3 additions & 3 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ from typing import ( # noqa: Y022
overload,
type_check_only,
)
from typing_extensions import ( # type: ignore
from typing_extensions import (
Concatenate,
Literal,
ParamSpec,
Expand Down Expand Up @@ -446,7 +446,7 @@ class str(Sequence[str]):
def expandtabs(self, tabsize: int = 8) -> str: ... # type: ignore[misc]

def find(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def format(self, *args: object, **kwargs: object) -> str: ... # type: ignore
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, map: _FormatMapMapping) -> str: ...
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
def isalnum(self) -> bool: ...
Expand Down Expand Up @@ -508,7 +508,7 @@ class str(Sequence[str]):
def __le__(self, __value: str) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, __value: str) -> bool: ...
def __mod__(self, __value: Any) -> str: ... # type: ignore
def __mod__(self, __value: Any) -> str: ...
def __mul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
def __ne__(self, __value: object) -> bool: ...
def __rmul__(self, __value: SupportsIndex) -> str: ... # type: ignore[misc]
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class _IncrementalDecoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...

class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
_is_text_encoding: bool
@property
def encode(self) -> _Encoder: ...
@property
Expand Down
10 changes: 5 additions & 5 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from typing import Any, Generic, NoReturn, TypeVar, overload
from typing_extensions import Self, SupportsIndex, final

Expand Down Expand Up @@ -299,10 +299,10 @@ class Counter(dict[_T, int], Generic[_T]):
def __pos__(self) -> Counter[_T]: ...
def __neg__(self) -> Counter[_T]: ...
# several type: ignores because __iadd__ is supposedly incompatible with __add__, etc.
def __iadd__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc]
def __isub__(self, other: Counter[_T]) -> Self: ...
def __iand__(self, other: Counter[_T]) -> Self: ...
def __ior__(self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc]
def __iadd__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[misc]
def __isub__(self, other: SupportsItems[_T, int]) -> Self: ...
def __iand__(self, other: SupportsItems[_T, int]) -> Self: ...
def __ior__(self, other: SupportsItems[_T, int]) -> Self: ... # type: ignore[override,misc]
if sys.version_info >= (3, 10):
def total(self) -> int: ...
def __le__(self, other: Counter[Any]) -> bool: ...
Expand Down
9 changes: 8 additions & 1 deletion mypy/typeshed/stdlib/email/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import sys
from _typeshed import Unused
from email import _ParamType
from email.charset import Charset
from typing import overload
Expand Down Expand Up @@ -51,7 +52,13 @@ else:
def mktime_tz(data: _PDTZ) -> int: ...
def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bool = False) -> str: ...
def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ...
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...

if sys.version_info >= (3, 12):
def localtime(dt: datetime.datetime | None = None, isdst: Unused = None) -> datetime.datetime: ...

else:
def localtime(dt: datetime.datetime | None = None, isdst: int = -1) -> datetime.datetime: ...

def make_msgid(idstring: str | None = None, domain: str | None = None) -> str: ...
def decode_rfc2231(s: str) -> tuple[str | None, str | None, str]: ...
def encode_rfc2231(s: str, charset: str | None = None, language: str | None = None) -> str: ...
Expand Down
11 changes: 10 additions & 1 deletion mypy/typeshed/stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import types
from _typeshed import SupportsKeysAndGetItem, Unused
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Iterable, Iterator, Mapping
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Generic, TypeVar, overload
from typing_extensions import Literal, Self, TypeAlias

Expand Down Expand Up @@ -34,6 +34,9 @@ if sys.version_info >= (3, 11):
"verify",
]

if sys.version_info >= (3, 12):
__all__ += ["pickle_by_enum_name", "pickle_by_global_name"]

_EnumMemberT = TypeVar("_EnumMemberT")
_EnumerationT = TypeVar("_EnumerationT", bound=type[Enum])

Expand Down Expand Up @@ -234,6 +237,8 @@ if sys.version_info >= (3, 11):
_value_: str
@_magic_enum_attr
def value(self) -> str: ...
@staticmethod
def _generate_next_value_(name: str, start: int, count: int, last_values: list[str]) -> str: ...

class EnumCheck(StrEnum):
CONTINUOUS: str
Expand Down Expand Up @@ -289,3 +294,7 @@ class auto(IntFlag):
@_magic_enum_attr
def value(self) -> Any: ...
def __new__(cls) -> Self: ...

if sys.version_info >= (3, 12):
def pickle_by_global_name(self: Enum, proto: int) -> str: ...
def pickle_by_enum_name(self: _EnumMemberT, proto: int) -> tuple[Callable[..., Any], tuple[type[_EnumMemberT], str]]: ...
39 changes: 26 additions & 13 deletions mypy/typeshed/stdlib/http/client.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import email.message
import io
import ssl
import sys
import types
from _typeshed import ReadableBuffer, SupportsRead, WriteableBuffer
from collections.abc import Callable, Iterable, Iterator, Mapping
Expand Down Expand Up @@ -175,19 +176,31 @@ class HTTPConnection:
class HTTPSConnection(HTTPConnection):
# Can be `None` if `.connect()` was not called:
sock: ssl.SSLSocket | Any
def __init__(
self,
host: str,
port: int | None = None,
key_file: str | None = None,
cert_file: str | None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
context: ssl.SSLContext | None = None,
check_hostname: bool | None = None,
blocksize: int = 8192,
) -> None: ...
if sys.version_info >= (3, 12):
def __init__(
self,
host: str,
port: str | None = None,
*,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
context: ssl.SSLContext | None = None,
blocksize: int = 8192,
) -> None: ...
else:
def __init__(
self,
host: str,
port: int | None = None,
key_file: str | None = None,
cert_file: str | None = None,
timeout: float | None = ...,
source_address: tuple[str, int] | None = None,
*,
context: ssl.SSLContext | None = None,
check_hostname: bool | None = None,
blocksize: int = 8192,
) -> None: ...

class HTTPException(Exception): ...

Expand Down
30 changes: 29 additions & 1 deletion mypy/typeshed/stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dis
import enum
import sys
import types
from _typeshed import StrPath
from collections import OrderedDict
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Mapping, Sequence, Set as AbstractSet
from types import (
Expand Down Expand Up @@ -127,8 +128,21 @@ if sys.version_info >= (3, 11):
"walktree",
]

if sys.version_info >= (3, 12):
__all__ += [
"markcoroutinefunction",
"AGEN_CLOSED",
"AGEN_CREATED",
"AGEN_RUNNING",
"AGEN_SUSPENDED",
"getasyncgenlocals",
"getasyncgenstate",
"BufferFlags",
]

_P = ParamSpec("_P")
_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., Any])
_T_cont = TypeVar("_T_cont", contravariant=True)
_V_cont = TypeVar("_V_cont", contravariant=True)

Expand Down Expand Up @@ -177,12 +191,15 @@ if sys.version_info >= (3, 11):
@overload
def getmembers_static(object: object, predicate: _GetMembersPredicate | None = None) -> _GetMembersReturn: ...

def getmodulename(path: str) -> str | None: ...
def getmodulename(path: StrPath) -> str | None: ...
def ismodule(object: object) -> TypeGuard[ModuleType]: ...
def isclass(object: object) -> TypeGuard[type[Any]]: ...
def ismethod(object: object) -> TypeGuard[MethodType]: ...
def isfunction(object: object) -> TypeGuard[FunctionType]: ...

if sys.version_info >= (3, 12):
def markcoroutinefunction(func: _F) -> _F: ...

if sys.version_info >= (3, 8):
@overload
def isgeneratorfunction(obj: Callable[..., Generator[Any, Any, Any]]) -> bool: ...
Expand Down Expand Up @@ -359,6 +376,17 @@ class _ParameterKind(enum.IntEnum):
@property
def description(self) -> str: ...

if sys.version_info >= (3, 12):
AGEN_CREATED: Literal["AGEN_CREATED"]
AGEN_RUNNING: Literal["AGEN_RUNNING"]
AGEN_SUSPENDED: Literal["AGEN_SUSPENDED"]
AGEN_CLOSED: Literal["AGEN_CLOSED"]

def getasyncgenstate(
agen: AsyncGenerator[Any, Any]
) -> Literal["AGEN_CREATED", "AGEN_RUNNING", "AGEN_SUSPENDED", "AGEN_CLOSED"]: ...
def getasyncgenlocals(agen: AsyncGeneratorType[Any, Any]) -> dict[str, Any]: ...

class Parameter:
def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ...
empty = _empty
Expand Down
30 changes: 23 additions & 7 deletions mypy/typeshed/stdlib/pydoc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,24 @@ def resolve(thing: str | object, forceload: bool = ...) -> tuple[object, str] |
def render_doc(
thing: str | object, title: str = "Python Library Documentation: %s", forceload: bool = ..., renderer: Doc | None = None
) -> str: ...
def doc(
thing: str | object,
title: str = "Python Library Documentation: %s",
forceload: bool = ...,
output: SupportsWrite[str] | None = None,
) -> None: ...

if sys.version_info >= (3, 12):
def doc(
thing: str | object,
title: str = "Python Library Documentation: %s",
forceload: bool = ...,
output: SupportsWrite[str] | None = None,
is_cli: bool = False,
) -> None: ...

else:
def doc(
thing: str | object,
title: str = "Python Library Documentation: %s",
forceload: bool = ...,
output: SupportsWrite[str] | None = None,
) -> None: ...

def writedoc(thing: str | object, forceload: bool = ...) -> None: ...
def writedocs(dir: str, pkgpath: str = "", done: Any | None = None) -> None: ...

Expand All @@ -216,7 +228,11 @@ class Helper:
def __call__(self, request: str | Helper | object = ...) -> None: ...
def interact(self) -> None: ...
def getline(self, prompt: str) -> str: ...
def help(self, request: Any) -> None: ...
if sys.version_info >= (3, 12):
def help(self, request: Any, is_cli: bool = False) -> None: ...
else:
def help(self, request: Any) -> None: ...

def intro(self) -> None: ...
def list(self, items: _list[str], columns: int = 4, width: int = 80) -> None: ...
def listkeywords(self) -> None: ...
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ if sys.version_info >= (3, 12):
ETHERTYPE_IPV6 as ETHERTYPE_IPV6,
ETHERTYPE_VLAN as ETHERTYPE_VLAN,
)
if sys.version_info >= (3, 11) and sys.platform == "darwin":
from _socket import TCP_CONNECTION_INFO as TCP_CONNECTION_INFO

# Re-exported from errno
EBADF: int
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/tempfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ else:
# It does not actually derive from IO[AnyStr], but it does mostly behave
# like one.
class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase):
_file: IO[AnyStr]
@property
def encoding(self) -> str: ... # undocumented
@property
Expand Down
Loading