Skip to content

Commit

Permalink
Sync typeshed (#15873)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Aug 15, 2023
1 parent 854a9f8 commit b49be10
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 32 deletions.
47 changes: 45 additions & 2 deletions mypy/typeshed/stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,48 @@ class BaseEventLoop(AbstractEventLoop):
flags: int = 0,
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = 0) -> tuple[str, str]: ...
if sys.version_info >= (3, 11):
if sys.version_info >= (3, 12):
@overload
async def create_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
host: str = ...,
port: int = ...,
*,
ssl: _SSLContext = None,
family: int = 0,
proto: int = 0,
flags: int = 0,
sock: None = None,
local_addr: tuple[str, int] | None = None,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
happy_eyeballs_delay: float | None = None,
interleave: int | None = None,
all_errors: bool = False,
) -> tuple[Transport, _ProtocolT]: ...
@overload
async def create_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
host: None = None,
port: None = None,
*,
ssl: _SSLContext = None,
family: int = 0,
proto: int = 0,
flags: int = 0,
sock: socket,
local_addr: None = None,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
happy_eyeballs_delay: float | None = None,
interleave: int | None = None,
all_errors: bool = False,
) -> tuple[Transport, _ProtocolT]: ...
elif sys.version_info >= (3, 11):
@overload
async def create_connection(
self,
Expand Down Expand Up @@ -426,5 +467,7 @@ class BaseEventLoop(AbstractEventLoop):
# Debug flag management.
def get_debug(self) -> bool: ...
def set_debug(self, enabled: bool) -> None: ...
if sys.version_info >= (3, 9):
if sys.version_info >= (3, 12):
async def shutdown_default_executor(self, timeout: float | None = None) -> None: ...
elif sys.version_info >= (3, 9):
async def shutdown_default_executor(self) -> None: ...
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/asyncio/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if sys.version_info >= (3, 11):
SSL_SHUTDOWN_TIMEOUT: float
FLOW_CONTROL_HIGH_WATER_SSL_READ: Literal[256]
FLOW_CONTROL_HIGH_WATER_SSL_WRITE: Literal[512]
if sys.version_info >= (3, 12):
THREAD_JOIN_TIMEOUT: Literal[300]

class _SendfileMode(enum.Enum):
UNSUPPORTED: int
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Handle:
def cancel(self) -> None: ...
def _run(self) -> None: ...
def cancelled(self) -> bool: ...
if sys.version_info >= (3, 12):
def get_context(self) -> Context: ...

class TimerHandle(Handle):
def __init__(
Expand Down
11 changes: 10 additions & 1 deletion mypy/typeshed/stdlib/asyncio/streams.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,16 @@ class StreamWriter:
async def wait_closed(self) -> None: ...
def get_extra_info(self, name: str, default: Any = None) -> Any: ...
async def drain(self) -> None: ...
if sys.version_info >= (3, 11):
if sys.version_info >= (3, 12):
async def start_tls(
self,
sslcontext: ssl.SSLContext,
*,
server_hostname: str | None = None,
ssl_handshake_timeout: float | None = None,
ssl_shutdown_timeout: float | None = None,
) -> None: ...
elif sys.version_info >= (3, 11):
async def start_tls(
self, sslcontext: ssl.SSLContext, *, server_hostname: str | None = None, ssl_handshake_timeout: float | None = None
) -> None: ...
Expand Down
23 changes: 22 additions & 1 deletion mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,26 @@ else:
# since the only reason why `asyncio.Future` is invariant is the `set_result()` method,
# and `asyncio.Task.set_result()` always raises.
class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
if sys.version_info >= (3, 8):
if sys.version_info >= (3, 12):
def __init__(
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
context: Context | None = None,
eager_start: bool = False,
) -> None: ...
elif sys.version_info >= (3, 11):
def __init__(
self,
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
context: Context | None = None,
) -> None: ...
elif sys.version_info >= (3, 8):
def __init__(
self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop = ..., name: str | None = ...
) -> None: ...
Expand All @@ -295,6 +314,8 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
def get_coro(self) -> _TaskCompatibleCoro[_T_co]: ...
def get_name(self) -> str: ...
def set_name(self, __value: object) -> None: ...
if sys.version_info >= (3, 12):
def get_context(self) -> Context: ...

def get_stack(self, *, limit: int | None = None) -> list[FrameType]: ...
def print_stack(self, *, limit: int | None = None, file: TextIO | None = None) -> None: ...
Expand Down
10 changes: 4 additions & 6 deletions mypy/typeshed/stdlib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _typeshed
import sys
import types
from _typeshed import SupportsKeysAndGetItem, Unused
from abc import ABCMeta
from builtins import property as _builtins_property
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Generic, TypeVar, overload
Expand Down Expand Up @@ -76,12 +75,8 @@ class _EnumDict(dict[str, Any]):
@overload
def update(self, members: Iterable[tuple[str, Any]], **more_members: Any) -> None: ...

# Note: EnumMeta actually subclasses type directly, not ABCMeta.
# This is a temporary workaround to allow multiple creation of enums with builtins
# such as str as mixins, which due to the handling of ABCs of builtin types, cause
# spurious inconsistent metaclass structure. See #1595.
# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself
class EnumMeta(ABCMeta):
class EnumMeta(type):
if sys.version_info >= (3, 11):
def __new__(
metacls: type[_typeshed.Self],
Expand Down Expand Up @@ -193,6 +188,9 @@ class Enum(metaclass=EnumMeta):
def __hash__(self) -> int: ...
def __format__(self, format_spec: str) -> str: ...
def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ...
if sys.version_info >= (3, 12):
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...

if sys.version_info >= (3, 11):
class ReprEnum(Enum): ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/importlib/metadata/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class MetadataPathFinder(DistributionFinder):
def invalidate_caches(cls) -> None: ...

class PathDistribution(Distribution):
_path: Path
def __init__(self, path: Path) -> None: ...
def read_text(self, filename: StrPath) -> str: ...
def locate_file(self, path: StrPath) -> PathLike[str]: ...
Expand Down
18 changes: 16 additions & 2 deletions mypy/typeshed/stdlib/logging/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ __all__ = [

if sys.version_info >= (3, 11):
__all__ += ["getLevelNamesMapping"]
if sys.version_info >= (3, 12):
__all__ += ["getHandlerByName", "getHandlerNames"]

_SysExcInfoType: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]
_ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException
Expand All @@ -83,7 +85,10 @@ class Filterer:
filters: list[_FilterType]
def addFilter(self, filter: _FilterType) -> None: ...
def removeFilter(self, filter: _FilterType) -> None: ...
def filter(self, record: LogRecord) -> bool: ...
if sys.version_info >= (3, 12):
def filter(self, record: LogRecord) -> bool | LogRecord: ...
else:
def filter(self, record: LogRecord) -> bool: ...

class Manager: # undocumented
root: RootLogger
Expand Down Expand Up @@ -111,6 +116,8 @@ class Logger(Filterer):
def isEnabledFor(self, level: int) -> bool: ...
def getEffectiveLevel(self) -> int: ...
def getChild(self, suffix: str) -> Self: ... # see python/typing#980
if sys.version_info >= (3, 12):
def getChildren(self) -> set[Logger]: ...
if sys.version_info >= (3, 8):
def debug(
self,
Expand Down Expand Up @@ -324,6 +331,10 @@ class Handler(Filterer):
def format(self, record: LogRecord) -> str: ...
def emit(self, record: LogRecord) -> None: ...

if sys.version_info >= (3, 12):
def getHandlerByName(name: str) -> Handler | None: ...
def getHandlerNames() -> frozenset[str]: ...

class Formatter:
converter: Callable[[float | None], struct_time]
_fmt: str | None # undocumented
Expand Down Expand Up @@ -370,7 +381,10 @@ class Filter:
name: str # undocumented
nlen: int # undocumented
def __init__(self, name: str = "") -> None: ...
def filter(self, record: LogRecord) -> bool: ...
if sys.version_info >= (3, 12):
def filter(self, record: LogRecord) -> bool | LogRecord: ...
else:
def filter(self, record: LogRecord) -> bool: ...

class LogRecord:
# args can be set to None by logging.handlers.QueueHandler
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
TCP_LINGER2 as TCP_LINGER2,
TCP_QUICKACK as TCP_QUICKACK,
TCP_SYNCNT as TCP_SYNCNT,
TCP_USER_TIMEOUT as TCP_USER_TIMEOUT,
TCP_WINDOW_CLAMP as TCP_WINDOW_CLAMP,
)
if sys.platform != "win32":
Expand Down
24 changes: 19 additions & 5 deletions mypy/typeshed/stdlib/sre_parse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,39 @@ class Tokenizer:
def seek(self, index: int) -> None: ...
def error(self, msg: str, offset: int = 0) -> _Error: ...

if sys.version_info >= (3, 11):
if sys.version_info >= (3, 12):
def checkgroupname(self, name: str, offset: int) -> None: ...
elif sys.version_info >= (3, 11):
def checkgroupname(self, name: str, offset: int, nested: int) -> None: ...

def fix_flags(src: str | bytes, flags: int) -> int: ...

_TemplateType: TypeAlias = tuple[list[tuple[int, int]], list[str | None]]
_TemplateByteType: TypeAlias = tuple[list[tuple[int, int]], list[bytes | None]]
if sys.version_info >= (3, 8):
def parse(str: str, flags: int = 0, state: State | None = None) -> SubPattern: ...

if sys.version_info >= (3, 12):
@overload
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
@overload
def parse_template(source: bytes, pattern: _Pattern[Any]) -> _TemplateByteType: ...

elif sys.version_info >= (3, 8):
@overload
def parse_template(source: str, state: _Pattern[Any]) -> _TemplateType: ...
@overload
def parse_template(source: bytes, state: _Pattern[Any]) -> _TemplateByteType: ...

else:
def parse(str: str, flags: int = 0, pattern: Pattern | None = None) -> SubPattern: ...
@overload
def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ...
@overload
def parse_template(source: bytes, pattern: _Pattern[Any]) -> _TemplateByteType: ...

def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...
if sys.version_info >= (3, 8):
def parse(str: str, flags: int = 0, state: State | None = None) -> SubPattern: ...

else:
def parse(str: str, flags: int = 0, pattern: Pattern | None = None) -> SubPattern: ...

if sys.version_info < (3, 12):
def expand_template(template: _TemplateType, match: Match[Any]) -> str: ...
41 changes: 28 additions & 13 deletions mypy/typeshed/stdlib/ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ class SSLCertVerificationError(SSLError, ValueError):

CertificateError = SSLCertVerificationError

def wrap_socket(
sock: socket.socket,
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
server_side: bool = False,
cert_reqs: int = ...,
ssl_version: int = ...,
ca_certs: str | None = None,
do_handshake_on_connect: bool = True,
suppress_ragged_eofs: bool = True,
ciphers: str | None = None,
) -> SSLSocket: ...
if sys.version_info < (3, 12):
def wrap_socket(
sock: socket.socket,
keyfile: StrOrBytesPath | None = None,
certfile: StrOrBytesPath | None = None,
server_side: bool = False,
cert_reqs: int = ...,
ssl_version: int = ...,
ca_certs: str | None = None,
do_handshake_on_connect: bool = True,
suppress_ragged_eofs: bool = True,
ciphers: str | None = None,
) -> SSLSocket: ...

def create_default_context(
purpose: Purpose = ...,
*,
Expand Down Expand Up @@ -95,7 +97,10 @@ else:
_create_default_https_context: Callable[..., SSLContext]

def RAND_bytes(__n: int) -> bytes: ...
def RAND_pseudo_bytes(__n: int) -> tuple[bytes, bool]: ...

if sys.version_info < (3, 12):
def RAND_pseudo_bytes(__n: int) -> tuple[bytes, bool]: ...

def RAND_status() -> bool: ...
def RAND_egd(path: str) -> None: ...
def RAND_add(__string: str | ReadableBuffer, __entropy: float) -> None: ...
Expand Down Expand Up @@ -198,6 +203,11 @@ class Options(enum.IntFlag):
OP_ENABLE_MIDDLEBOX_COMPAT: int
if sys.platform == "linux":
OP_IGNORE_UNEXPECTED_EOF: int
if sys.version_info >= (3, 12):
OP_LEGACY_SERVER_CONNECT: int
if sys.version_info >= (3, 12) and sys.platform != "linux":
OP_ENABLE_KTLS: int
OP_IGNORE_UNEXPECTED_EOF: int

OP_ALL: Options
OP_NO_SSLv2: Options
Expand All @@ -216,6 +226,11 @@ if sys.version_info >= (3, 8):
OP_ENABLE_MIDDLEBOX_COMPAT: Options
if sys.platform == "linux":
OP_IGNORE_UNEXPECTED_EOF: Options
if sys.version_info >= (3, 12):
OP_LEGACY_SERVER_CONNECT: Options
if sys.version_info >= (3, 12) and sys.platform != "linux":
OP_ENABLE_KTLS: Options
OP_IGNORE_UNEXPECTED_EOF: Options

HAS_NEVER_CHECK_COMMON_NAME: bool
HAS_SSLv2: bool
Expand Down
7 changes: 7 additions & 0 deletions mypy/typeshed/stdlib/turtle.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from collections.abc import Callable, Sequence
from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar
from typing import Any, ClassVar, overload
Expand Down Expand Up @@ -249,6 +250,9 @@ class TNavigator:
def reset(self) -> None: ...
def degrees(self, fullcircle: float = 360.0) -> None: ...
def radians(self) -> None: ...
if sys.version_info >= (3, 12):
def teleport(self, x: float | None = None, y: float | None = None, *, fill_gap: bool = False) -> None: ...

def forward(self, distance: float) -> None: ...
def back(self, distance: float) -> None: ...
def right(self, angle: float) -> None: ...
Expand Down Expand Up @@ -321,6 +325,9 @@ class TPen:
def color(self, r: float, g: float, b: float) -> None: ...
@overload
def color(self, color1: _Color, color2: _Color) -> None: ...
if sys.version_info >= (3, 12):
def teleport(self, x: float | None = None, y: float | None = None, *, fill_gap: bool = False) -> None: ...

def showturtle(self) -> None: ...
def hideturtle(self) -> None: ...
def isvisible(self) -> bool: ...
Expand Down
10 changes: 9 additions & 1 deletion mypy/typeshed/stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
@overload
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
@overload
def __ror__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
@overload
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
# supposedly incompatible definitions of __or__ and __ior__
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... # type: ignore[misc]

@_final
class ForwardRef:
Expand Down
Loading

0 comments on commit b49be10

Please sign in to comment.