1616 cast ,
1717)
1818
19- import anyio
2019import httpx
21- from anyio .to_thread import run_sync
22- from anyio .from_thread import threadlocals
23- from anyio .from_thread import run as run_async
2420
2521from githubkit .utils import is_async
2622from githubkit .exception import AuthExpiredError
2723
2824from .base import BaseAuthStrategy
2925from ._url import require_bypass , get_oauth_base_url , require_basic_auth
3026
27+ try :
28+ import anyio
29+ from anyio .to_thread import run_sync
30+ from anyio .from_thread import threadlocals
31+ from anyio .from_thread import run as run_async
32+ except ImportError :
33+ anyio = None
34+ run_sync = None
35+ run_async = None
36+ threadlocals = None
37+
3138if TYPE_CHECKING :
3239 from githubkit import GitHubCore
3340
@@ -262,6 +269,11 @@ def _parse_response_data(self, data: Dict[str, Any]) -> str:
262269
263270 def call_handler (self , data : Dict [str , Any ]) -> None :
264271 if is_async (self .on_verification ):
272+ if anyio is None or threadlocals is None or run_async is None :
273+ raise RuntimeError (
274+ "AnyIO support for OAuth Device Callback should be installed "
275+ "with `pip install githubkit[auth-oauth-device]`"
276+ )
265277 handler = cast (
266278 Callable [[Dict [str , Any ]], Coroutine [None , None , None ]],
267279 self .on_verification ,
@@ -284,6 +296,11 @@ async def acall_handler(self, data: Dict[str, Any]) -> None:
284296 )
285297 await handler (data )
286298 else :
299+ if run_sync is None :
300+ raise RuntimeError (
301+ "AnyIO support for OAuth Device Callback should be installed "
302+ "with `pip install githubkit[auth-oauth-device]`"
303+ )
287304 handler = cast (Callable [[Dict [str , Any ]], None ], self .on_verification )
288305 await run_sync (handler , data )
289306
0 commit comments