Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(api): Improve sentry_sdk.trace type hints #2633

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix typing when trace called with None
  • Loading branch information
szokeasaurusrex committed Jan 16, 2024
commit 27bdc377fdfcf0b796aba87a6229b8c77423e5c0
12 changes: 7 additions & 5 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
if TYPE_CHECKING:
import typing

from collections.abc import Callable

Check warning on line 17 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L17

Added line #L17 was not covered by tests
from typing import Any
from typing import Dict
from typing import Iterator
from typing import List
from typing import Optional
from typing import overload
from typing import ParamSpec

Check warning on line 24 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L23-L24

Added lines #L23 - L24 were not covered by tests
from typing import Tuple
from typing import Union
from typing import TypeVar

Check warning on line 27 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L27

Added line #L27 was not covered by tests

T = TypeVar("T", bound=Callable[..., Any])
P = ParamSpec("P")
R = TypeVar("R")

Check warning on line 30 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L29-L30

Added lines #L29 - L30 were not covered by tests

import sentry_sdk.profiler
from sentry_sdk._types import Event, MeasurementUnit, SamplingContext
Expand Down Expand Up @@ -990,19 +992,19 @@

if TYPE_CHECKING:

@overload

Check warning on line 995 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L995

Added line #L995 was not covered by tests
def trace(func):
# type: (None) -> Callable[[Any], Any]
def trace(func=None):
# type: (None) -> Callable[[Callable[P, R]], Callable[P, R]]
pass

Check warning on line 998 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L998

Added line #L998 was not covered by tests

@overload

Check warning on line 1000 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L1000

Added line #L1000 was not covered by tests
def trace(func):
# type: (T) -> T
# type: (Callable[P, R]) -> Callable[P, R]
pass

Check warning on line 1003 in sentry_sdk/tracing.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/tracing.py#L1003

Added line #L1003 was not covered by tests


def trace(func=None):
# type: (Optional[T]) -> Union[T, Callable[[Any], Any]]
# type: (Optional[Callable[P, R]]) -> Union[Callable[P, R], Callable[[Callable[P, R]], Callable[P, R]]]
"""
Decorator to start a child span under the existing current transaction.
If there is no current transaction, then nothing will be traced.
Expand Down
Loading