diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 2c75e7b37..08c3f2c8b 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -5,7 +5,7 @@ import types from _typeshed import Self, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from socket import socket -from typing import IO, Any, BinaryIO, Protocol, TypeVar, overload +from typing import IO, Any, BinaryIO, TypeVar, overload from typing_extensions import TypeAlias __all__ = [ @@ -137,18 +137,6 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): def getcode(self) -> int: ... def begin(self) -> None: ... -# This is an API stub only for the class below, not a class itself. -# urllib.request uses it for a parameter. -class _HTTPConnectionProtocol(Protocol): - def __call__( - self, - host: str, - port: int | None = ..., - timeout: float = ..., - source_address: tuple[str, int] | None = ..., - blocksize: int = ..., - ) -> HTTPConnection: ... - class HTTPConnection: auto_open: int # undocumented debuglevel: int diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index 42b56d88d..b46d42a41 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -85,9 +85,6 @@ class Loader(metaclass=ABCMeta): # but expected in new code. def exec_module(self, module: types.ModuleType) -> None: ... -class _LoaderProtocol(Protocol): - def load_module(self, fullname: str) -> types.ModuleType: ... - class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): name: str path: _Path diff --git a/stdlib/types.pyi b/stdlib/types.pyi index 1af4420e6..28fce697f 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -13,11 +13,10 @@ from collections.abc import ( MutableSequence, ValuesView, ) -from importlib.abc import _LoaderProtocol from importlib.machinery import ModuleSpec # pytype crashes if types.MappingProxyType inherits from collections.abc.Mapping instead of typing.Mapping -from typing import Any, ClassVar, Generic, Mapping, TypeVar, overload # noqa: Y027 +from typing import Any, ClassVar, Generic, Mapping, Protocol, TypeVar, overload # noqa: Y027 from typing_extensions import Literal, ParamSpec, final __all__ = [ @@ -325,6 +324,9 @@ class SimpleNamespace: def __setattr__(self, __name: str, __value: Any) -> None: ... def __delattr__(self, __name: str) -> None: ... +class _LoaderProtocol(Protocol): + def load_module(self, fullname: str) -> ModuleType: ... + class ModuleType: __name__: str __file__: str | None diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index 0ad10a218..88f4f5250 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -3,10 +3,10 @@ import sys from _typeshed import StrOrBytesPath, SupportsRead from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from email.message import Message -from http.client import HTTPMessage, HTTPResponse, _HTTPConnectionProtocol +from http.client import HTTPConnection, HTTPMessage, HTTPResponse from http.cookiejar import CookieJar from re import Pattern -from typing import IO, Any, ClassVar, NoReturn, TypeVar, overload +from typing import IO, Any, ClassVar, NoReturn, Protocol, TypeVar, overload from typing_extensions import TypeAlias from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl @@ -224,6 +224,16 @@ class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header: ClassVar[str] # undocumented def http_error_407(self, req: Request, fp: IO[bytes], code: int, msg: str, headers: HTTPMessage) -> _UrlopenRet | None: ... +class _HTTPConnectionProtocol(Protocol): + def __call__( + self, + host: str, + port: int | None = ..., + timeout: float = ..., + source_address: tuple[str, int] | None = ..., + blocksize: int = ..., + ) -> HTTPConnection: ... + class AbstractHTTPHandler(BaseHandler): # undocumented def __init__(self, debuglevel: int = ...) -> None: ... def set_http_debuglevel(self, level: int) -> None: ...