Skip to content

Commit 6929430

Browse files
committed
fix type annotation
1 parent c21cf48 commit 6929430

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pydantic_ai_slim/pydantic_ai/common_tools/duckduckgo.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import functools
44
from dataclasses import KW_ONLY, dataclass
5+
from typing import TYPE_CHECKING
56

67
import anyio
78
import anyio.to_thread
@@ -10,16 +11,19 @@
1011

1112
from pydantic_ai.tools import Tool
1213

13-
try:
14+
if TYPE_CHECKING:
15+
from ddgs import DDGS
16+
else:
1417
try:
15-
from ddgs import DDGS
16-
except ImportError: # Fallback for older versions of ddgs
17-
from duckduckgo_search import DDGS
18-
except ImportError as _import_error:
19-
raise ImportError(
20-
'Please install `ddgs` to use the DuckDuckGo search tool, '
21-
'you can use the `duckduckgo` optional group — `pip install "pydantic-ai-slim[duckduckgo]"`'
22-
) from _import_error
18+
try:
19+
from ddgs import DDGS
20+
except ImportError: # Fallback for older versions of ddgs
21+
from duckduckgo_search import DDGS
22+
except ImportError as _import_error:
23+
raise ImportError(
24+
'Please install `ddgs` to use the DuckDuckGo search tool, '
25+
'you can use the `duckduckgo` optional group — `pip install "pydantic-ai-slim[duckduckgo]"`'
26+
) from _import_error
2327

2428
__all__ = ('duckduckgo_search_tool',)
2529

0 commit comments

Comments
 (0)