Skip to content

Commit c8a83aa

Browse files
authored
Turn ParamSpec non-private (#361)
1 parent f4d434d commit c8a83aa

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

logfire-api/logfire_api/_internal/instrument.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ from .ast_utils import BaseTransformer as BaseTransformer, LogfireArgs as Logfir
33
from .main import Logfire as Logfire
44
from dataclasses import dataclass
55
from types import CodeType
6-
from typing import Callable
6+
from typing import Callable, TypeVar
7+
from typing_extensions import ParamSpec
78

8-
def instrument(logfire: Logfire, args: LogfireArgs) -> Callable[[Callable[_PARAMS, _RETURN]], Callable[_PARAMS, _RETURN]]: ...
9+
P = ParamSpec('P')
10+
R = TypeVar('R')
11+
12+
def instrument(logfire: Logfire, args: LogfireArgs) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
913
def transform_code(func_code: CodeType, args: LogfireArgs): ...
1014

1115
@dataclass

logfire-api/logfire_api/_internal/main.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from starlette.applications import Starlette
3535
from starlette.requests import Request as Request
3636
from starlette.websockets import WebSocket as WebSocket
3737
from typing import Any, Callable, ContextManager, Iterable, Literal, Sequence, TypeVar
38-
from typing_extensions import LiteralString, Unpack
38+
from typing_extensions import LiteralString, ParamSpec, Unpack
3939

4040
ExcInfo = SysExcInfo | BaseException | bool | None
4141

@@ -216,7 +216,7 @@ class Logfire:
216216
attributes: The arguments to include in the span and format the message template with.
217217
Attributes starting with an underscore are not allowed.
218218
"""
219-
def instrument(self, msg_template: LiteralString | None = None, *, span_name: str | None = None, extract_args: bool = True) -> Callable[[Callable[_PARAMS, _RETURN]], Callable[_PARAMS, _RETURN]]:
219+
def instrument(self, msg_template: LiteralString | None = None, *, span_name: str | None = None, extract_args: bool = True) -> Callable[[Callable[P, R]], Callable[P, R]]:
220220
"""Decorator for instrumenting a function as a span.
221221
222222
```py
@@ -961,3 +961,5 @@ def set_user_attribute(otlp_attributes: dict[str, otel_types.AttributeValue], ke
961961
Returns the final key and value that was added to the dictionary.
962962
The key will be the original key unless the value was `None`, in which case it will be `NULL_ARGS_KEY`.
963963
"""
964+
P = ParamSpec('P')
965+
R = TypeVar('R')

logfire/_internal/instrument.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
from .main import Logfire
1717

1818

19-
_PARAMS = ParamSpec('_PARAMS')
20-
_RETURN = TypeVar('_RETURN')
19+
P = ParamSpec('P')
20+
R = TypeVar('R')
2121

2222

23-
def instrument(
24-
logfire: Logfire,
25-
args: LogfireArgs,
26-
) -> Callable[[Callable[_PARAMS, _RETURN]], Callable[_PARAMS, _RETURN]]:
27-
def decorator(func: Callable[_PARAMS, _RETURN]) -> Callable[_PARAMS, _RETURN]:
23+
def instrument(logfire: Logfire, args: LogfireArgs) -> Callable[[Callable[P, R]], Callable[P, R]]:
24+
def decorator(func: Callable[P, R]) -> Callable[P, R]:
2825
# This creates a new function object with code compiled from a modified AST
2926
# from the original function's source code.
3027
# Since this doesn't wrap/call the original function,

logfire/_internal/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def instrument(
519519
*,
520520
span_name: str | None = None,
521521
extract_args: bool = True,
522-
) -> Callable[[Callable[_PARAMS, _RETURN]], Callable[_PARAMS, _RETURN]]:
522+
) -> Callable[[Callable[P, R]], Callable[P, R]]:
523523
"""Decorator for instrumenting a function as a span.
524524
525525
```py
@@ -1867,5 +1867,5 @@ def set_user_attribute(
18671867
return key, otel_value
18681868

18691869

1870-
_PARAMS = ParamSpec('_PARAMS')
1871-
_RETURN = TypeVar('_RETURN')
1870+
P = ParamSpec('P')
1871+
R = TypeVar('R')

0 commit comments

Comments
 (0)