From d7ab30e65a168c7663e4bd29146bc7cfbabc32a4 Mon Sep 17 00:00:00 2001 From: gngpp Date: Tue, 7 Apr 2026 19:54:19 +0800 Subject: [PATCH 1/2] docs(python): prefer `Mapping` over `Dict` for abstract type hints --- python/wreq/header.py | 4 ++-- python/wreq/proxy.py | 4 ++-- python/wreq/wreq.py | 21 +++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/python/wreq/header.py b/python/wreq/header.py index 50d44d13..22291ae1 100644 --- a/python/wreq/header.py +++ b/python/wreq/header.py @@ -11,7 +11,7 @@ Set-Cookie, Accept-Encoding, etc.). """ -from typing import Dict, Iterator, Sequence, Tuple +from typing import Mapping, Iterator, Sequence, Tuple __all__ = ["HeaderMap", "OrigHeaderMap"] @@ -58,7 +58,7 @@ def __str__(self) -> str: ... def __init__( - self, init: Dict[str, str] | None = None, capacity: int | None = None + self, init: Mapping[str, str] | None = None, capacity: int | None = None ) -> None: """ Create a new HeaderMap. diff --git a/python/wreq/proxy.py b/python/wreq/proxy.py index 768a1674..2f7e03d7 100644 --- a/python/wreq/proxy.py +++ b/python/wreq/proxy.py @@ -1,4 +1,4 @@ -from typing import Dict, NotRequired, TypedDict, Unpack, final +from typing import Mapping, NotRequired, TypedDict, Unpack, final from wreq.header import HeaderMap @@ -15,7 +15,7 @@ class ProxyConfig(TypedDict): custom_http_auth: NotRequired[str] r"""Custom HTTP proxy authentication header value.""" - custom_http_headers: NotRequired[Dict[str, str] | HeaderMap] + custom_http_headers: NotRequired[Mapping[str, str] | HeaderMap] r"""Custom HTTP proxy headers.""" exclusion: NotRequired[str] diff --git a/python/wreq/wreq.py b/python/wreq/wreq.py index 2be42022..08aa1bd9 100644 --- a/python/wreq/wreq.py +++ b/python/wreq/wreq.py @@ -5,10 +5,11 @@ from typing import ( Any, AsyncGenerator, - Dict, + Mapping, Generator, NotRequired, Sequence, + Mapping, Tuple, TypedDict, Unpack, @@ -527,7 +528,7 @@ class ClientConfig(TypedDict): Sets the `User-Agent` header to be used by this client. """ - headers: NotRequired[Dict[str, str] | HeaderMap] + headers: NotRequired[Mapping[str, str] | HeaderMap] """ Sets the default headers for every request. """ @@ -795,7 +796,7 @@ class Request(TypedDict): The Emulation settings for the request. """ - headers: NotRequired[Dict[str, str] | HeaderMap] + headers: NotRequired[Mapping[str, str] | HeaderMap] """ The headers to use for the request. """ @@ -810,7 +811,7 @@ class Request(TypedDict): The option enables default headers. """ - cookies: NotRequired[str | Dict[str, str]] + cookies: NotRequired[str | Mapping[str, str]] """ The cookies to use for the request. """ @@ -916,7 +917,7 @@ class Request(TypedDict): query: NotRequired[ Sequence[Tuple[str, str | int | float | bool]] - | Dict[str, str | int | float | bool] + | Mapping[str, str | int | float | bool] ] """ The query parameters to use for the request. @@ -924,7 +925,7 @@ class Request(TypedDict): form: NotRequired[ Sequence[Tuple[str, str | int | float | bool]] - | Dict[str, str | int | float | bool] + | Mapping[str, str | int | float | bool] ] """ The form parameters to use for the request. @@ -940,7 +941,7 @@ class Request(TypedDict): | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] - | Dict[str, str | int | float | bool] + | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str] @@ -981,7 +982,7 @@ class WebSocketRequest(TypedDict): Bind to an interface by SO_BINDTODEVICE. """ - headers: NotRequired[Dict[str, str] | HeaderMap] + headers: NotRequired[Mapping[str, str] | HeaderMap] """ The headers to use for the request. """ @@ -996,7 +997,7 @@ class WebSocketRequest(TypedDict): The option enables default headers. """ - cookies: NotRequired[str | Dict[str, str]] + cookies: NotRequired[str | Mapping[str, str]] """ The cookies to use for the request. """ @@ -1028,7 +1029,7 @@ class WebSocketRequest(TypedDict): query: NotRequired[ Sequence[Tuple[str, str | int | float | bool]] - | Dict[str, str | int | float | bool] + | Mapping[str, str | int | float | bool] ] """ The query parameters to use for the request. From 4956ec16f5f2290c16ebb95276ad3758dc7480d6 Mon Sep 17 00:00:00 2001 From: 0x676e67 Date: Tue, 7 Apr 2026 19:57:47 +0800 Subject: [PATCH 2/2] Update wreq.py --- python/wreq/wreq.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/wreq/wreq.py b/python/wreq/wreq.py index 08aa1bd9..52584323 100644 --- a/python/wreq/wreq.py +++ b/python/wreq/wreq.py @@ -5,7 +5,6 @@ from typing import ( Any, AsyncGenerator, - Mapping, Generator, NotRequired, Sequence,