From f06b78a01bf3142f7fe215eccdfd7eca1abd4e38 Mon Sep 17 00:00:00 2001 From: Harith Nabil <205104106+harithnabilf@users.noreply.github.com> Date: Sun, 29 Nov 2026 11:42:54 +0800 Subject: [PATCH] [httplib2] Annotate proxy and TLS settings --- stubs/httplib2/httplib2/__init__.pyi | 72 ++++++++++++++++++---------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/stubs/httplib2/httplib2/__init__.pyi b/stubs/httplib2/httplib2/__init__.pyi index dbded2b43d0b..3b084e76a392 100644 --- a/stubs/httplib2/httplib2/__init__.pyi +++ b/stubs/httplib2/httplib2/__init__.pyi @@ -4,9 +4,9 @@ import http.client import re from _ssl import _PasswordType from _typeshed import ConvertibleToFloat, ConvertibleToInt, FloatInt, Incomplete, MaybeNone, StrOrBytesPath -from collections.abc import Generator -from ssl import _SSLMethod -from typing import Any, ClassVar, Final, Literal, TypeVar, overload +from collections.abc import Callable, Generator, Sequence +from ssl import TLSVersion, _SSLMethod +from typing import Any, ClassVar, Final, Literal, TypeAlias, TypeVar, overload from typing_extensions import Self from .error import * @@ -15,6 +15,8 @@ _T = TypeVar("_T", default=str) _R = TypeVar("_R") _D = TypeVar("_D") +_ProxyInfoFactory: TypeAlias = Callable[[Literal["http", "https"]], ProxyInfo | None] + __author__: Final[str] __copyright__: Final[str] __contributors__: Final[list[str]] @@ -127,28 +129,47 @@ class KeyCerts(Credentials): class AllHosts: ... class ProxyInfo: - bypass_hosts: Incomplete + bypass_hosts: Sequence[str] | type[AllHosts] + proxy_type: int + proxy_host: str | None + proxy_port: int | None + proxy_rdns: bool + proxy_user: str | None + proxy_pass: str | None + proxy_headers: Incomplete | None # stored but never sent by httplib2 def __init__( - self, proxy_type, proxy_host, proxy_port, proxy_rdns: bool = True, proxy_user=None, proxy_pass=None, proxy_headers=None + self, + proxy_type: int, + proxy_host: str | None, + proxy_port: int | None, + proxy_rdns: bool = True, + proxy_user: str | bytes | None = None, + proxy_pass: str | bytes | None = None, + proxy_headers=None, ) -> None: ... - def astuple(self): ... - def isgood(self): ... - def applies_to(self, hostname): ... - def bypass_host(self, hostname): ... + def astuple(self) -> tuple[int, str | None, int | None, bool, str | None, str | None, Incomplete | None]: ... + def isgood(self) -> bool | None: ... # None if PySocks is not installed + def applies_to(self, hostname: str) -> bool: ... + def bypass_host(self, hostname: str) -> bool: ... def proxy_info_from_environment(method: Literal["http", "https"] = "http") -> ProxyInfo | None: ... def proxy_info_from_url(url: str, method: Literal["http", "https"] = "http", noproxy: str | None = None) -> ProxyInfo: ... class HTTPConnectionWithTimeout(http.client.HTTPConnection): - proxy_info: Incomplete - def __init__(self, host, port=None, timeout=None, proxy_info=None) -> None: ... - sock: Incomplete + proxy_info: ProxyInfo | None + def __init__( + self, + host: str, + port: int | None = None, + timeout: FloatInt | None = None, + proxy_info: ProxyInfo | _ProxyInfoFactory | None = None, + ) -> None: ... def connect(self) -> None: ... class HTTPSConnectionWithTimeout(http.client.HTTPSConnection): disable_ssl_certificate_validation: bool ca_certs: StrOrBytesPath | None - proxy_info: Incomplete + proxy_info: ProxyInfo | None key_file: StrOrBytesPath | None cert_file: StrOrBytesPath | None key_password: _PasswordType | None @@ -159,25 +180,24 @@ class HTTPSConnectionWithTimeout(http.client.HTTPSConnection): key_file: StrOrBytesPath | None = None, cert_file: StrOrBytesPath | None = None, timeout: FloatInt | None = None, - proxy_info=None, + proxy_info: ProxyInfo | _ProxyInfoFactory | None = None, ca_certs: StrOrBytesPath | None = None, disable_ssl_certificate_validation: bool = False, - tls_maximum_version=None, - tls_minimum_version=None, + tls_maximum_version: TLSVersion | str | None = None, + tls_minimum_version: TLSVersion | str | None = None, key_password: _PasswordType | None = None, ) -> None: ... - sock: Incomplete def connect(self) -> None: ... SCHEME_TO_CONNECTION: Final[dict[Literal["http", "https"], type[http.client.HTTPConnection]]] class Http: - proxy_info: Incomplete - ca_certs: Incomplete + proxy_info: ProxyInfo | _ProxyInfoFactory | None + ca_certs: StrOrBytesPath | None disable_ssl_certificate_validation: bool - tls_maximum_version: Incomplete - tls_minimum_version: Incomplete - connections: Incomplete + tls_maximum_version: TLSVersion | str | None + tls_minimum_version: TLSVersion | str | None + connections: dict[str, http.client.HTTPConnection] cache: FileCache credentials: Credentials certificates: KeyCerts @@ -196,11 +216,11 @@ class Http: self, cache: str | FileCache | None = None, timeout: FloatInt | None = None, - proxy_info=..., - ca_certs=None, + proxy_info: ProxyInfo | _ProxyInfoFactory | None = ..., + ca_certs: StrOrBytesPath | None = None, disable_ssl_certificate_validation: bool = False, - tls_maximum_version=None, - tls_minimum_version=None, + tls_maximum_version: TLSVersion | str | None = None, + tls_minimum_version: TLSVersion | str | None = None, decode_limit_hard: ConvertibleToInt | None = None, decode_limit_safe: ConvertibleToInt | None = None, decode_limit_ratio: ConvertibleToFloat | None = None,