Skip to content

Commit f4d434d

Browse files
authored
Remove TypeAlias from code source (#359)
1 parent 09634b0 commit f4d434d

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

logfire-api/logfire_api/_internal/main.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import anthropic
22
import openai
33
import opentelemetry.trace as trace_api
4-
import typing
54
from . import async_ as async_
65
from ..version import VERSION as VERSION
76
from .auto_trace import AutoTraceModule as AutoTraceModule, install_auto_tracing as install_auto_tracing
@@ -38,7 +37,7 @@ from starlette.websockets import WebSocket as WebSocket
3837
from typing import Any, Callable, ContextManager, Iterable, Literal, Sequence, TypeVar
3938
from typing_extensions import LiteralString, Unpack
4039

41-
ExcInfo: typing.TypeAlias
40+
ExcInfo = SysExcInfo | BaseException | bool | None
4241

4342
class Logfire:
4443
"""The main logfire class."""

logfire-api/logfire_api/_internal/utils.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import typing
21
from _typeshed import Incomplete
32
from collections.abc import Generator
43
from logfire._internal.stack_info import is_user_code as is_user_code
@@ -11,8 +10,10 @@ from opentelemetry.util import types as otel_types
1110
from packaging.version import Version
1211
from pathlib import Path
1312
from requests import RequestException, Response
13+
from types import TracebackType
1414
from typing import Any, Mapping, Sequence, TypeVar, TypedDict
1515

16+
SysExcInfo = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None]
1617
T = TypeVar('T')
1718
JsonValue: Incomplete
1819
JsonDict = dict[str, JsonValue]
@@ -84,8 +85,5 @@ def is_instrumentation_suppressed() -> bool:
8485
def suppress_instrumentation() -> Generator[None, None, None]:
8586
"""Context manager to suppress all logs/spans generated by logfire or OpenTelemetry."""
8687
def log_internal_error() -> None: ...
87-
88-
SysExcInfo: typing.TypeAlias
89-
9088
def handle_internal_errors() -> Generator[None, None, None]: ...
9189
def maybe_capture_server_headers(capture: bool): ...

logfire/_internal/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import sys
66
import traceback
7-
import typing
87
import warnings
98
from functools import cached_property, partial
109
from time import time
@@ -51,7 +50,7 @@
5150
from .metrics import ProxyMeterProvider
5251
from .stack_info import get_user_stack_info
5352
from .tracer import ProxyTracerProvider
54-
from .utils import SysExcInfo, handle_internal_errors, log_internal_error, uniquify_sequence
53+
from .utils import handle_internal_errors, log_internal_error, uniquify_sequence
5554

5655
if TYPE_CHECKING:
5756
import anthropic
@@ -75,20 +74,21 @@
7574
from .integrations.redis import RedisInstrumentKwargs
7675
from .integrations.sqlalchemy import SQLAlchemyInstrumentKwargs
7776
from .integrations.starlette import StarletteInstrumentKwargs
77+
from .utils import SysExcInfo
78+
79+
# This is the type of the exc_info/_exc_info parameter of the log methods.
80+
# sys.exc_info() returns a tuple of (type, value, traceback) or (None, None, None).
81+
# We just need the exception, but we allow the user to pass the tuple because:
82+
# 1. It's convenient to pass the result of sys.exc_info() directly
83+
# 2. It mirrors the exc_info argument of the stdlib logging methods
84+
# 3. The argument name exc_info is very suggestive of the sys function.
85+
ExcInfo = Union[SysExcInfo, BaseException, bool, None]
7886

7987
try:
8088
from pydantic import ValidationError
8189
except ImportError: # pragma: no cover
8290
ValidationError = None
8391

84-
# This is the type of the exc_info/_exc_info parameter of the log methods.
85-
# sys.exc_info() returns a tuple of (type, value, traceback) or (None, None, None).
86-
# We just need the exception, but we allow the user to pass the tuple because:
87-
# 1. It's convenient to pass the result of sys.exc_info() directly
88-
# 2. It mirrors the exc_info argument of the stdlib logging methods
89-
# 3. The argument name exc_info is very suggestive of the sys function.
90-
ExcInfo: typing.TypeAlias = Union[SysExcInfo, BaseException, bool, None]
91-
9292

9393
class Logfire:
9494
"""The main logfire class."""

logfire/_internal/utils.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66
import os
77
import sys
8-
import typing
98
from contextlib import contextmanager
109
from pathlib import Path
1110
from types import TracebackType
@@ -24,6 +23,11 @@
2423
if TYPE_CHECKING:
2524
from packaging.version import Version
2625

26+
SysExcInfo = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]]
27+
"""
28+
The return type of sys.exc_info(): exc_type, exc_val, exc_tb.
29+
"""
30+
2731
T = TypeVar('T')
2832

2933
JsonValue = Union[int, float, str, bool, None, List['JsonValue'], Tuple['JsonValue', ...], 'JsonDict']
@@ -260,15 +264,6 @@ def log_internal_error():
260264
logger.exception('Internal error in Logfire', exc_info=_internal_error_exc_info())
261265

262266

263-
SysExcInfo: typing.TypeAlias = Union[
264-
'tuple[type[BaseException], BaseException, TracebackType | None]',
265-
'tuple[None, None, None]',
266-
]
267-
"""
268-
The return type of sys.exc_info(): exc_type, exc_val, exc_tb.
269-
"""
270-
271-
272267
def _internal_error_exc_info() -> SysExcInfo:
273268
"""Returns an exc_info tuple with a nicely tweaked traceback."""
274269
original_exc_info: SysExcInfo = sys.exc_info()

0 commit comments

Comments
 (0)