♻️ Add compatibility with the next version of AnyIO (#1936)

This commit is contained in:
Sebastián Ramírez 2022-11-04 23:58:00 +01:00 committed by GitHub
parent fbab16a2b1
commit a45027209a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from types import GeneratorType
from urllib.parse import unquote, urljoin
import anyio
import anyio.from_thread
import httpx
from anyio.streams.stapled import StapledObjectStream
@ -398,7 +399,9 @@ class TestClient(httpx.Client):
if self.portal is not None:
yield self.portal
else:
with anyio.start_blocking_portal(**self.async_backend) as portal:
with anyio.from_thread.start_blocking_portal(
**self.async_backend
) as portal:
yield portal
def _choose_redirect_arg(
@ -714,7 +717,7 @@ class TestClient(httpx.Client):
def __enter__(self) -> "TestClient":
with contextlib.ExitStack() as stack:
self.portal = portal = stack.enter_context(
anyio.start_blocking_portal(**self.async_backend)
anyio.from_thread.start_blocking_portal(**self.async_backend)
)
@stack.callback