From a570fb6ced7cab7e03d7cbf0ba008124cf696476 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 10 Sep 2023 22:54:43 +0100 Subject: [PATCH] Fix various stubtest complaints on Python 3.12 (#10691) --- stdlib/http/client.pyi | 3 +++ stdlib/imaplib.pyi | 11 ++++++++--- stdlib/turtle.pyi | 6 ++++++ stdlib/urllib/request.pyi | 18 ++++++++++++++---- tests/stubtest_allowlists/py312.txt | 8 -------- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 4b5ed3d8b..3e5e496ab 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -169,6 +169,9 @@ class HTTPConnection: ) -> None: ... def getresponse(self) -> HTTPResponse: ... def set_debuglevel(self, level: int) -> None: ... + if sys.version_info >= (3, 12): + def get_proxy_response_headers(self) -> HTTPMessage | None: ... + def set_tunnel(self, host: str, port: int | None = None, headers: Mapping[str, str] | None = None) -> None: ... def connect(self) -> None: ... def close(self) -> None: ... diff --git a/stdlib/imaplib.pyi b/stdlib/imaplib.pyi index 7781559c3..a61848c9a 100644 --- a/stdlib/imaplib.pyi +++ b/stdlib/imaplib.pyi @@ -108,9 +108,14 @@ class IMAP4: def print_log(self) -> None: ... class IMAP4_SSL(IMAP4): - keyfile: str - certfile: str - if sys.version_info >= (3, 9): + if sys.version_info < (3, 12): + keyfile: str + certfile: str + if sys.version_info >= (3, 12): + def __init__( + self, host: str = "", port: int = 993, *, ssl_context: SSLContext | None = None, timeout: float | None = None + ) -> None: ... + elif sys.version_info >= (3, 9): def __init__( self, host: str = "", diff --git a/stdlib/turtle.pyi b/stdlib/turtle.pyi index 80ea40879..36cd5f1f6 100644 --- a/stdlib/turtle.pyi +++ b/stdlib/turtle.pyi @@ -129,6 +129,9 @@ __all__ = [ "Terminator", ] +if sys.version_info >= (3, 12): + __all__ += ["teleport"] + # Note: '_Color' is the alias we use for arguments and _AnyColor is the # alias we use for return types. Really, these two aliases should be the # same, but as per the "no union returns" typeshed policy, we'll return @@ -648,6 +651,9 @@ def shape(name: None = None) -> str: ... @overload def shape(name: str) -> None: ... +if sys.version_info >= (3, 12): + def teleport(x: float | None = None, y: float | None = None, *, fill_gap: bool = False) -> None: ... + # Unsafely overlaps when no arguments are provided @overload def shapesize() -> tuple[float, float, float]: ... # type: ignore[misc] diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index 079c97555..a4849dfa2 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -235,7 +235,11 @@ class _HTTPConnectionProtocol(Protocol): ) -> HTTPConnection: ... class AbstractHTTPHandler(BaseHandler): # undocumented - def __init__(self, debuglevel: int = 0) -> None: ... + if sys.version_info >= (3, 12): + def __init__(self, debuglevel: int | None = None) -> None: ... + else: + def __init__(self, debuglevel: int = 0) -> None: ... + def set_http_debuglevel(self, level: int) -> None: ... def do_request_(self, request: Request) -> Request: ... def do_open(self, http_class: _HTTPConnectionProtocol, req: Request, **http_conn_args: Any) -> HTTPResponse: ... @@ -245,9 +249,15 @@ class HTTPHandler(AbstractHTTPHandler): def http_request(self, request: Request) -> Request: ... # undocumented class HTTPSHandler(AbstractHTTPHandler): - def __init__( - self, debuglevel: int = 0, context: ssl.SSLContext | None = None, check_hostname: bool | None = None - ) -> None: ... + if sys.version_info >= (3, 12): + def __init__( + self, debuglevel: int | None = None, context: ssl.SSLContext | None = None, check_hostname: bool | None = None + ) -> None: ... + else: + def __init__( + self, debuglevel: int = 0, context: ssl.SSLContext | None = None, check_hostname: bool | None = None + ) -> None: ... + def https_open(self, req: Request) -> HTTPResponse: ... def https_request(self, request: Request) -> Request: ... # undocumented diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index dda993743..606c63212 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -3,14 +3,6 @@ enum.Enum.__signature__ enum.EnumMeta.__call__ enum.EnumType.__call__ enum.property.member -http.client.HTTPConnection.get_proxy_response_headers -imaplib.IMAP4_SSL.__init__ -urllib.request.AbstractHTTPHandler.__init__ -urllib.request.HTTPSHandler.__init__ - -# TODO: remove after rc2 release -turtle.__all__ -turtle.teleport # Errors that also existed on Python 3.11 _collections_abc.AsyncIterable.__class_getitem__