Skip to content

Commit 5c855fd

Browse files
committed
Fixes
1 parent 17bd5fe commit 5c855fd

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

pydantic_evals/pydantic_evals/_utils.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import warnings
66
from collections.abc import Awaitable, Callable, Generator, Sequence
77
from contextlib import contextmanager
8-
from functools import partial, wraps
8+
from functools import partial
99
from pathlib import Path
10-
from typing import Any, TypeVar
10+
from typing import TYPE_CHECKING, Any, TypeVar
1111

1212
import anyio
1313
import logfire_api
@@ -114,18 +114,22 @@ async def _run_task(tsk: Callable[[], Awaitable[T]], index: int) -> None:
114114
from logfire._internal.config import (
115115
LogfireNotConfiguredWarning, # pyright: ignore[reportAssignmentType,reportPrivateImportUsage]
116116
)
117-
except ImportError:
117+
# TODO: Remove this once we test evals without pydantic-ai (which includes logfire)
118+
except ImportError: # pragma: no cover
118119

119120
class LogfireNotConfiguredWarning(UserWarning):
120121
pass
121122

122123

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

pydantic_graph/pydantic_graph/_utils.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import warnings
66
from collections.abc import Callable, Generator
77
from contextlib import contextmanager
8-
from functools import partial, wraps
8+
from functools import partial
99
from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar, get_args, get_origin
1010

1111
from logfire_api import Logfire, LogfireSpan
@@ -151,12 +151,15 @@ class LogfireNotConfiguredWarning(UserWarning):
151151
pass
152152

153153

154-
@wraps(_logfire.span)
155-
@contextmanager
156-
def logfire_span(*args: Any, **kwargs: Any) -> Generator[LogfireSpan, None, None]:
157-
"""Create a Logfire span without warning if logfire is not configured."""
158-
# TODO: Remove once Logfire has the ability to suppress this warning from non-user code
159-
with warnings.catch_warnings():
160-
warnings.filterwarnings('ignore', category=LogfireNotConfiguredWarning)
161-
with _logfire.span(*args, **kwargs) as span:
162-
yield span
154+
if TYPE_CHECKING:
155+
logfire_span = _logfire.span
156+
else:
157+
158+
@contextmanager
159+
def logfire_span(*args: Any, **kwargs: Any) -> Generator[LogfireSpan, None, None]:
160+
"""Create a Logfire span without warning if logfire is not configured."""
161+
# TODO: Remove once Logfire has the ability to suppress this warning from non-user code
162+
with warnings.catch_warnings():
163+
warnings.filterwarnings('ignore', category=LogfireNotConfiguredWarning)
164+
with _logfire.span(*args, **kwargs) as span:
165+
yield span

0 commit comments

Comments
 (0)