Skip to content

Commit 2fd20bb

Browse files
committed
BREAK: remove the request_with functionality 💥
It used to be a workaround in the early versions and is not needed now
1 parent e8daf6e commit 2fd20bb

File tree

7 files changed

+29
-86
lines changed

7 files changed

+29
-86
lines changed

combadge/support/httpx/backends/async_.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

3-
from contextlib import AbstractAsyncContextManager
43
from types import TracebackType
5-
from typing import Any, Callable
4+
from typing import Any
65

76
from httpx import AsyncClient, Response
87
from pydantic import TypeAdapter
@@ -14,32 +13,27 @@
1413
from combadge.core.signature import Signature
1514
from combadge.support.http.request import Request
1615
from combadge.support.httpx.backends.base import BaseHttpxBackend
17-
from combadge.support.shared.async_ import SupportsRequestWith
18-
from combadge.support.shared.contextlib import asyncnullcontext
1916

2017

21-
class HttpxBackend(BaseHttpxBackend[AsyncClient], SupportsRequestWith[Request], ServiceContainer):
18+
class HttpxBackend(BaseHttpxBackend[AsyncClient], ServiceContainer):
2219
"""Async HTTPX backend."""
2320

24-
__slots__ = ("_client", "_request_with", "_service_cache", "_raise_for_status")
21+
__slots__ = ("_client", "_service_cache", "_raise_for_status")
2522

2623
def __init__(
2724
self,
2825
client: AsyncClient,
2926
*,
30-
request_with: Callable[[Any], AbstractAsyncContextManager] = asyncnullcontext,
3127
raise_for_status: bool = True,
3228
) -> None:
3329
"""
3430
Instantiate the backend.
3531
3632
Args:
3733
client: [HTTPX client](https://www.python-httpx.org/advanced/#client-instances)
38-
request_with: an optional context manager getter to wrap each request into
3934
raise_for_status: automatically call `raise_for_status()`
4035
"""
4136
BaseHttpxBackend.__init__(self, client, raise_for_status=raise_for_status)
42-
SupportsRequestWith.__init__(self, request_with)
4337
ServiceContainer.__init__(self)
4438

4539
def bind_method(self, signature: Signature) -> ServiceMethod[HttpxBackend]: # noqa: D102
@@ -48,15 +42,14 @@ def bind_method(self, signature: Signature) -> ServiceMethod[HttpxBackend]: # n
4842

4943
async def bound_method(self: BaseBoundService[HttpxBackend], *args: Any, **kwargs: Any) -> Any:
5044
request = signature.build_request(Request, self, args, kwargs)
51-
async with self.backend._request_with(request):
52-
response: Response = await backend._client.request(
53-
request.get_method(),
54-
request.get_url_path(),
55-
json=request.payload,
56-
data=request.form_data,
57-
params=request.query_params,
58-
headers=request.headers,
59-
)
45+
response: Response = await backend._client.request(
46+
request.get_method(),
47+
request.get_url_path(),
48+
json=request.payload,
49+
data=request.form_data,
50+
params=request.query_params,
51+
headers=request.headers,
52+
)
6053
return signature.apply_response_markers(response, backend._parse_response(response), response_type)
6154

6255
return bound_method # type: ignore[return-value]

combadge/support/httpx/backends/sync.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

3-
from contextlib import AbstractContextManager, nullcontext
43
from types import TracebackType
5-
from typing import Any, Callable
4+
from typing import Any
65

76
from httpx import Client, Response
87
from pydantic import TypeAdapter
@@ -14,31 +13,27 @@
1413
from combadge.core.signature import Signature
1514
from combadge.support.http.request import Request
1615
from combadge.support.httpx.backends.base import BaseHttpxBackend
17-
from combadge.support.shared.sync import SupportsRequestWith
1816

1917

20-
class HttpxBackend(BaseHttpxBackend[Client], SupportsRequestWith[Request], ServiceContainer):
18+
class HttpxBackend(BaseHttpxBackend[Client], ServiceContainer):
2119
"""Sync HTTPX backend."""
2220

23-
__slots__ = ("_client", "_request_with", "_service_cache", "_raise_for_status")
21+
__slots__ = ("_client", "_service_cache", "_raise_for_status")
2422

2523
def __init__(
2624
self,
2725
client: Client,
2826
*,
29-
request_with: Callable[[Any], AbstractContextManager] = nullcontext,
3027
raise_for_status: bool = True,
3128
) -> None:
3229
"""
3330
Instantiate the backend.
3431
3532
Args:
3633
client: [HTTPX client](https://www.python-httpx.org/advanced/#client-instances)
37-
request_with: an optional context manager getter to wrap each request into
3834
raise_for_status: automatically call `raise_for_status()`
3935
"""
4036
BaseHttpxBackend.__init__(self, client, raise_for_status=raise_for_status)
41-
SupportsRequestWith.__init__(self, request_with)
4237
ServiceContainer.__init__(self)
4338

4439
def bind_method(self, signature: Signature) -> ServiceMethod[HttpxBackend]: # noqa: D102
@@ -47,15 +42,14 @@ def bind_method(self, signature: Signature) -> ServiceMethod[HttpxBackend]: # n
4742

4843
def bound_method(self: BaseBoundService[HttpxBackend], *args: Any, **kwargs: Any) -> Any:
4944
request = signature.build_request(Request, self, args, kwargs)
50-
with self.backend._request_with(request):
51-
response: Response = backend._client.request(
52-
request.get_method(),
53-
request.get_url_path(),
54-
json=request.payload,
55-
data=request.form_data,
56-
params=request.query_params,
57-
headers=request.headers,
58-
)
45+
response: Response = backend._client.request(
46+
request.get_method(),
47+
request.get_url_path(),
48+
json=request.payload,
49+
data=request.form_data,
50+
params=request.query_params,
51+
headers=request.headers,
52+
)
5953
return signature.apply_response_markers(response, backend._parse_response(response), response_type)
6054

6155
return bound_method # type: ignore[return-value]

combadge/support/shared/async_.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

combadge/support/shared/contextlib.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

combadge/support/shared/sync.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

combadge/support/zeep/backends/async_.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

33
from collections.abc import Collection
4-
from contextlib import AbstractAsyncContextManager
54
from os import PathLike, fspath
65
from ssl import SSLContext
76
from types import TracebackType
8-
from typing import Any, Callable
7+
from typing import Any
98

109
import httpx
1110
from typing_extensions import Self
@@ -20,20 +19,17 @@
2019
from combadge.core.binder import BaseBoundService
2120
from combadge.core.interfaces import ServiceMethod
2221
from combadge.core.signature import Signature
23-
from combadge.support.shared.async_ import SupportsRequestWith
24-
from combadge.support.shared.contextlib import asyncnullcontext
2522
from combadge.support.soap.request import Request
2623
from combadge.support.zeep.backends.base import BaseZeepBackend, ByBindingName, ByServiceName
2724

2825

2926
class ZeepBackend(
3027
BaseZeepBackend[AsyncServiceProxy, AsyncOperationProxy],
31-
SupportsRequestWith[Request],
3228
ServiceContainer,
3329
):
3430
"""Asynchronous Zeep service."""
3531

36-
__slots__ = ("_service", "_request_with", "_service_cache")
32+
__slots__ = ("_service", "_service_cache")
3733

3834
@classmethod
3935
def with_params(
@@ -90,18 +86,14 @@ def with_params(
9086
def __init__(
9187
self,
9288
service: AsyncServiceProxy,
93-
*,
94-
request_with: Callable[[Any], AbstractAsyncContextManager] = asyncnullcontext,
9589
) -> None:
9690
"""
9791
Instantiate the backend.
9892
9993
Args:
10094
service: [service proxy object](https://docs.python-zeep.org/en/master/client.html#the-serviceproxy-object)
101-
request_with: an optional context manager getter to wrap each request into
10295
"""
10396
BaseZeepBackend.__init__(self, service)
104-
SupportsRequestWith.__init__(self, request_with)
10597
ServiceContainer.__init__(self)
10698

10799
def bind_method(self, signature: Signature) -> ServiceMethod[ZeepBackend]: # noqa: D102
@@ -112,8 +104,7 @@ async def bound_method(self: BaseBoundService[ZeepBackend], *args: Any, **kwargs
112104
request = signature.build_request(Request, self, args, kwargs)
113105
operation = backend._get_operation(request.get_operation_name())
114106
try:
115-
async with self.backend._request_with(request):
116-
response = await operation(**(request.payload or {}))
107+
response = await operation(**(request.payload or {}))
117108
except Fault as e:
118109
return backend._parse_soap_fault(e, fault_type)
119110
else:

combadge/support/zeep/backends/sync.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from contextlib import AbstractContextManager, nullcontext
43
from os import PathLike, fspath
54
from types import TracebackType
6-
from typing import Any, Callable, Collection
5+
from typing import Any, Collection
76

87
from typing_extensions import Self
98
from zeep import Client, Plugin, Transport
@@ -16,15 +15,14 @@
1615
from combadge.core.binder import BaseBoundService
1716
from combadge.core.interfaces import ServiceMethod
1817
from combadge.core.signature import Signature
19-
from combadge.support.shared.sync import SupportsRequestWith
2018
from combadge.support.soap.request import Request
2119
from combadge.support.zeep.backends.base import BaseZeepBackend, ByBindingName, ByServiceName
2220

2321

24-
class ZeepBackend(BaseZeepBackend[ServiceProxy, OperationProxy], SupportsRequestWith[Request], ServiceContainer):
22+
class ZeepBackend(BaseZeepBackend[ServiceProxy, OperationProxy], ServiceContainer):
2523
"""Synchronous Zeep service."""
2624

27-
__slots__ = ("_service", "_request_with", "_service_cache")
25+
__slots__ = ("_service", "_service_cache")
2826

2927
@classmethod
3028
def with_params(
@@ -69,18 +67,14 @@ def with_params(
6967
def __init__(
7068
self,
7169
service: ServiceProxy,
72-
*,
73-
request_with: Callable[[Any], AbstractContextManager] = nullcontext,
7470
) -> None:
7571
"""
7672
Instantiate the backend.
7773
7874
Args:
7975
service: [service proxy object](https://docs.python-zeep.org/en/master/client.html#the-serviceproxy-object)
80-
request_with: an optional context manager getter to wrap each request into
8176
"""
8277
BaseZeepBackend.__init__(self, service)
83-
SupportsRequestWith.__init__(self, request_with)
8478
ServiceContainer.__init__(self)
8579

8680
def bind_method(self, signature: Signature) -> ServiceMethod[ZeepBackend]: # noqa: D102
@@ -91,8 +85,7 @@ def bound_method(self: BaseBoundService[ZeepBackend], *args: Any, **kwargs: Any)
9185
request = signature.build_request(Request, self, args, kwargs)
9286
operation = backend._get_operation(request.get_operation_name())
9387
try:
94-
with self.backend._request_with(request):
95-
response = operation(**(request.payload or {}))
88+
response = operation(**(request.payload or {}))
9689
except Fault as e:
9790
return backend._parse_soap_fault(e, fault_type)
9891
else:

0 commit comments

Comments
 (0)