From 2a1769f099d357fc0007f10be6e1ca2f36135721 Mon Sep 17 00:00:00 2001 From: gngpp Date: Tue, 14 Apr 2026 20:01:27 +0800 Subject: [PATCH] fix(client): correct handling of `Sequence[Proxy]` types --- python/wreq/wreq.py | 2 +- src/client.rs | 7 ++++--- src/client/resp/http.rs | 1 + src/extractor.rs | 21 +-------------------- src/macros.rs | 4 ++-- 5 files changed, 9 insertions(+), 26 deletions(-) diff --git a/python/wreq/wreq.py b/python/wreq/wreq.py index 8603e131..3a0878b4 100644 --- a/python/wreq/wreq.py +++ b/python/wreq/wreq.py @@ -715,7 +715,7 @@ class ClientConfig(TypedDict): proxies: NotRequired[Sequence[Proxy]] """ - Add a `Proxy` list to the client. + The proxies to use for requests. """ local_address: NotRequired[IPv4Address | IPv6Address] diff --git a/src/client.rs b/src/client.rs index 6da0938b..7fd63d3b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -15,7 +15,7 @@ use std::{ use pyo3::{IntoPyObjectExt, coroutine::CancelHandle, prelude::*, pybacked::PyBackedStr}; use req::{Request, WebSocketRequest}; use tokio_util::sync::CancellationToken; -use wreq::{Proxy, tls::trust::CertStore}; +use wreq::tls::trust::CertStore; use self::{ nogil::NoGIL, @@ -32,6 +32,7 @@ use crate::{ http::Method, http1::Http1Options, http2::Http2Options, + proxy::Proxy, redirect, tls::{Identity, KeyLog, TlsOptions, TlsVerify, TlsVersion}, }; @@ -141,8 +142,8 @@ struct Builder { // ========= Network options ========= /// Whether to disable the proxy for the client. no_proxy: Option, - /// The proxy to use for the client. - proxies: Option>>, + /// The proxies to use for the client. + proxies: Option>, /// Bind to a local IP Address. local_address: Option, /// Bind to local IP Addresses (IPv4, IPv6). diff --git a/src/client/resp/http.rs b/src/client/resp/http.rs index 21e51ddb..af178452 100644 --- a/src/client/resp/http.rs +++ b/src/client/resp/http.rs @@ -290,6 +290,7 @@ impl Display for Response { } impl Drop for Response { + #[inline] fn drop(&mut self) { self.destroy(); } diff --git a/src/extractor.rs b/src/extractor.rs index 003d0ba6..229e920c 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -1,29 +1,10 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; -use pyo3::{FromPyObject, prelude::*, types::PyList}; - -use crate::proxy::Proxy; +use pyo3::{FromPyObject, prelude::*}; /// A generic extractor for various types. pub struct Extractor(pub T); -impl FromPyObject<'_, '_> for Extractor> { - type Error = PyErr; - - fn extract(ob: Borrowed) -> PyResult { - let proxies = ob.cast::()?; - let len = proxies.len(); - proxies - .iter() - .try_fold(Vec::with_capacity(len), |mut list, proxy| { - let proxy = proxy.cast::()?; - list.push(proxy.borrow().0.clone()); - Ok::<_, PyErr>(list) - }) - .map(Self) - } -} - impl FromPyObject<'_, '_> for Extractor<(Option, Option)> { type Error = PyErr; diff --git a/src/macros.rs b/src/macros.rs index 4aeab982..38f74385 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -54,8 +54,8 @@ macro_rules! apply_option { }; (set_if_some_iter_inner, $builder:expr, $option:expr, $method:ident) => { if let Some(value) = $option.take() { - for item in value.0 { - $builder = $builder.$method(item); + for item in value { + $builder = $builder.$method(item.0); } } };