Skip to content

Commit ab6bd09

Browse files
committed
Defer httpx ImportError to instantiation time for Sphinx compatibility
The module-level ImportError prevented Sphinx autodoc from importing async_client when httpx is not installed. Now the module imports successfully (setting httpx=None) and raises ImportError only when AsyncAnticaptchaClient is instantiated without httpx. https://claude.ai/code/session_01Pimg4VAco2v4srPeZj44Zm
1 parent 88fbf31 commit ab6bd09

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

python_anticaptcha/async_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
try:
1010
import httpx
1111
except ImportError:
12-
raise ImportError(
13-
"httpx is required for async support. "
14-
"Install it with: pip install python-anticaptcha[async]"
15-
)
12+
httpx = None # type: ignore[assignment]
1613

1714
from .exceptions import AnticaptchaException
1815
from .tasks import BaseTask
@@ -130,6 +127,11 @@ def __init__(
130127
host: str = "api.anti-captcha.com",
131128
use_ssl: bool = True,
132129
) -> None:
130+
if httpx is None:
131+
raise ImportError(
132+
"httpx is required for async support. "
133+
"Install it with: pip install python-anticaptcha[async]"
134+
)
133135
self.client_key = client_key or os.environ.get("ANTICAPTCHA_API_KEY")
134136
if not self.client_key:
135137
raise AnticaptchaException(

0 commit comments

Comments
 (0)