Skip to content

Commit d8a81a9

Browse files
authored
Revert autocomplete hack (#2224)
1 parent 978a07f commit d8a81a9

File tree

3 files changed

+66
-58
lines changed

3 files changed

+66
-58
lines changed

sentry_sdk/api.py

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import inspect
2-
from functools import partial
32

43
from sentry_sdk._types import TYPE_CHECKING
54
from sentry_sdk.hub import Hub
65
from sentry_sdk.scope import Scope
7-
from sentry_sdk.tracing import Transaction
6+
from sentry_sdk.tracing import NoOpSpan, Transaction
87

98
if TYPE_CHECKING:
109
from typing import Any
@@ -14,8 +13,16 @@
1413
from typing import Callable
1514
from typing import TypeVar
1615
from typing import ContextManager
17-
18-
from sentry_sdk._types import MeasurementUnit
16+
from typing import Union
17+
18+
from sentry_sdk._types import (
19+
Event,
20+
Hint,
21+
Breadcrumb,
22+
BreadcrumbHint,
23+
ExcInfo,
24+
MeasurementUnit,
25+
)
1926
from sentry_sdk.tracing import Span
2027

2128
T = TypeVar("T")
@@ -70,36 +77,46 @@ def scopemethod(f):
7077
return f
7178

7279

73-
# Alias these functions to have nice auto completion for the arguments without
74-
# having to specify them here. The `partial(..., None)` hack is needed for Sphinx
75-
# to generate proper docs for these.
76-
if TYPE_CHECKING:
77-
capture_event = partial(Hub.capture_event, None)
78-
capture_message = partial(Hub.capture_message, None)
79-
capture_exception = partial(Hub.capture_exception, None)
80-
add_breadcrumb = partial(Hub.add_breadcrumb, None)
81-
start_span = partial(Hub.start_span, None)
82-
start_transaction = partial(Hub.start_transaction, None)
83-
84-
else:
80+
@hubmethod
81+
def capture_event(
82+
event, # type: Event
83+
hint=None, # type: Optional[Hint]
84+
scope=None, # type: Optional[Any]
85+
**scope_args # type: Any
86+
):
87+
# type: (...) -> Optional[str]
88+
return Hub.current.capture_event(event, hint, scope=scope, **scope_args)
8589

86-
def capture_event(*args, **kwargs):
87-
return Hub.current.capture_event(*args, **kwargs)
8890

89-
def capture_message(*args, **kwargs):
90-
return Hub.current.capture_message(*args, **kwargs)
91+
@hubmethod
92+
def capture_message(
93+
message, # type: str
94+
level=None, # type: Optional[str]
95+
scope=None, # type: Optional[Any]
96+
**scope_args # type: Any
97+
):
98+
# type: (...) -> Optional[str]
99+
return Hub.current.capture_message(message, level, scope=scope, **scope_args)
91100

92-
def capture_exception(*args, **kwargs):
93-
return Hub.current.capture_exception(*args, **kwargs)
94101

95-
def add_breadcrumb(*args, **kwargs):
96-
return Hub.current.add_breadcrumb(*args, **kwargs)
102+
@hubmethod
103+
def capture_exception(
104+
error=None, # type: Optional[Union[BaseException, ExcInfo]]
105+
scope=None, # type: Optional[Any]
106+
**scope_args # type: Any
107+
):
108+
# type: (...) -> Optional[str]
109+
return Hub.current.capture_exception(error, scope=scope, **scope_args)
97110

98-
def start_span(*args, **kwargs):
99-
return Hub.current.start_span(*args, **kwargs)
100111

101-
def start_transaction(*args, **kwargs):
102-
return Hub.current.start_transaction(*args, **kwargs)
112+
@hubmethod
113+
def add_breadcrumb(
114+
crumb=None, # type: Optional[Breadcrumb]
115+
hint=None, # type: Optional[BreadcrumbHint]
116+
**kwargs # type: Any
117+
):
118+
# type: (...) -> None
119+
return Hub.current.add_breadcrumb(crumb, hint, **kwargs)
103120

104121

105122
@overload
@@ -191,6 +208,24 @@ def last_event_id():
191208
return Hub.current.last_event_id()
192209

193210

211+
@hubmethod
212+
def start_span(
213+
span=None, # type: Optional[Span]
214+
**kwargs # type: Any
215+
):
216+
# type: (...) -> Span
217+
return Hub.current.start_span(span=span, **kwargs)
218+
219+
220+
@hubmethod
221+
def start_transaction(
222+
transaction=None, # type: Optional[Transaction]
223+
**kwargs # type: Any
224+
):
225+
# type: (...) -> Union[Transaction, NoOpSpan]
226+
return Hub.current.start_transaction(transaction, **kwargs)
227+
228+
194229
def set_measurement(name, value, unit=""):
195230
# type: (str, float, MeasurementUnit) -> None
196231
transaction = Hub.current.scope.transaction

sentry_sdk/hub.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -416,48 +416,22 @@ def _capture_internal_exception(
416416
"""
417417
logger.error("Internal error in sentry_sdk", exc_info=exc_info)
418418

419-
def add_breadcrumb(
420-
self,
421-
crumb=None, # type: Optional[Breadcrumb]
422-
hint=None, # type: Optional[BreadcrumbHint]
423-
timestamp=None, # type: Optional[datetime]
424-
type=None, # type: Optional[str]
425-
data=None, # type: Optional[Dict[str, Any]]
426-
**kwargs # type: Any
427-
):
428-
# type: (...) -> None
419+
def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
420+
# type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
429421
"""
430422
Adds a breadcrumb.
431423
432-
:param crumb: Dictionary with the data as the Sentry v7/v8 protocol expects.
424+
:param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.
433425
434426
:param hint: An optional value that can be used by `before_breadcrumb`
435427
to customize the breadcrumbs that are emitted.
436-
437-
:param timestamp: The timestamp associated with this breadcrumb. Defaults
438-
to now if not provided.
439-
440-
:param type: The type of the breadcrumb. Will be set to "default" if
441-
not provided.
442-
443-
:param data: Additional custom data to put on the breadcrumb.
444-
445-
:param kwargs: Adding any further keyword arguments will not result in
446-
an error, but the breadcrumb will be dropped before arriving to
447-
Sentry.
448428
"""
449429
client, scope = self._stack[-1]
450430
if client is None:
451431
logger.info("Dropped breadcrumb because no client bound")
452432
return
453433

454434
crumb = dict(crumb or ()) # type: Breadcrumb
455-
if timestamp is not None:
456-
crumb["timestamp"] = timestamp
457-
if type is not None:
458-
crumb["type"] = type
459-
if data is not None:
460-
crumb["data"] = data
461435
crumb.update(kwargs)
462436
if not crumb:
463437
return

sentry_sdk/tracing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ def my_function():
837837
@sentry_sdk.trace
838838
async def my_async_function():
839839
...
840-
841840
"""
842841
if PY2:
843842
from sentry_sdk.tracing_utils_py2 import start_child_span_decorator

0 commit comments

Comments
 (0)