Skip to content

Commit 0239c8c

Browse files
Move current_async_library to different PR
1 parent 81a49c9 commit 0239c8c

File tree

3 files changed

+7
-58
lines changed

3 files changed

+7
-58
lines changed

httpcore/_backends/auto.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import typing
22
from typing import Optional
33

4-
from .._synchronization import current_async_library
4+
from .._synchronization import current_async_backend
55
from .base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream
66

77

88
class AutoBackend(AsyncNetworkBackend):
99
async def _init_backend(self) -> None:
1010
if not (hasattr(self, "_backend")):
11-
backend = current_async_library()
11+
backend = current_async_backend()
1212
if backend == "trio":
1313
from .trio import TrioBackend
1414

httpcore/_synchronization.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import os
32
import threading
43
from types import TracebackType
54
from typing import (
@@ -31,7 +30,6 @@
3130

3231

3332
AsyncBackend = Literal["asyncio", "trio"]
34-
AsyncLibrary = Literal["asyncio", "trio", "anyio"]
3533

3634

3735
def current_async_backend() -> AsyncBackend:
@@ -47,6 +45,11 @@ def current_async_backend() -> AsyncBackend:
4745
if environment not in ("asyncio", "trio"): # pragma: nocover
4846
raise RuntimeError("Running under an unsupported async environment.")
4947

48+
if environment == "asyncio" and anyio is None: # pragma: nocover
49+
raise RuntimeError(
50+
"Running with asyncio requires installation of 'httpcore[asyncio]'."
51+
)
52+
5053
if environment == "trio" and trio is None: # pragma: nocover
5154
raise RuntimeError(
5255
"Running with trio requires installation of 'httpcore[trio]'."
@@ -55,18 +58,6 @@ def current_async_backend() -> AsyncBackend:
5558
return environment
5659

5760

58-
def current_async_library() -> AsyncLibrary:
59-
if current_async_backend() == "trio":
60-
return "trio"
61-
62-
if anyio is not None:
63-
anyio_env = os.environ.get("HTTPCORE_PREFER_ANYIO", "true").lower()
64-
if anyio_env in ("true", "1"):
65-
return "anyio"
66-
67-
return "asyncio"
68-
69-
7061
class _LockProto(Protocol):
7162
async def acquire(self) -> Any: ...
7263
def release(self) -> None: ...

tests/test_synchronization.py

-42
This file was deleted.

0 commit comments

Comments
 (0)