|
5 | 5 | import warnings |
6 | 6 | from collections.abc import Awaitable, Callable, Generator, Sequence |
7 | 7 | from contextlib import contextmanager |
8 | | -from functools import partial, wraps |
| 8 | +from functools import partial |
9 | 9 | from pathlib import Path |
10 | | -from typing import Any, TypeVar |
| 10 | +from typing import TYPE_CHECKING, Any, TypeVar |
11 | 11 |
|
12 | 12 | import anyio |
13 | 13 | import logfire_api |
@@ -114,18 +114,22 @@ async def _run_task(tsk: Callable[[], Awaitable[T]], index: int) -> None: |
114 | 114 | from logfire._internal.config import ( |
115 | 115 | LogfireNotConfiguredWarning, # pyright: ignore[reportAssignmentType,reportPrivateImportUsage] |
116 | 116 | ) |
117 | | -except ImportError: |
| 117 | +# TODO: Remove this once we test evals without pydantic-ai (which includes logfire) |
| 118 | +except ImportError: # pragma: no cover |
118 | 119 |
|
119 | 120 | class LogfireNotConfiguredWarning(UserWarning): |
120 | 121 | pass |
121 | 122 |
|
122 | 123 |
|
123 | | -@wraps(_logfire.span) |
124 | | -@contextmanager |
125 | | -def logfire_span(*args: Any, **kwargs: Any) -> Generator[logfire_api.LogfireSpan, None, None]: |
126 | | - """Create a Logfire span without warning if logfire is not configured.""" |
127 | | - # TODO: Remove once Logfire has the ability to suppress this warning from non-user code |
128 | | - with warnings.catch_warnings(): |
129 | | - warnings.filterwarnings('ignore', category=LogfireNotConfiguredWarning) |
130 | | - with _logfire.span(*args, **kwargs) as span: |
131 | | - yield span |
| 124 | +if TYPE_CHECKING: |
| 125 | + logfire_span = _logfire.span |
| 126 | +else: |
| 127 | + |
| 128 | + @contextmanager |
| 129 | + def logfire_span(*args: Any, **kwargs: Any) -> Generator[logfire_api.LogfireSpan, None, None]: |
| 130 | + """Create a Logfire span without warning if logfire is not configured.""" |
| 131 | + # TODO: Remove once Logfire has the ability to suppress this warning from non-user code |
| 132 | + with warnings.catch_warnings(): |
| 133 | + warnings.filterwarnings('ignore', category=LogfireNotConfiguredWarning) |
| 134 | + with _logfire.span(*args, **kwargs) as span: |
| 135 | + yield span |
0 commit comments