Skip to content

Commit 8a95971

Browse files
docs(init): Fix sentry_sdk.init type hint (#3283)
The current type hint suggests that all the parameters can be passed as positional arguments, when this is not the case. Only the `dsn` can be passed as a positional argument; the rest must be passed as keyword arguments. This PR makes the type hint reflect the reality of what parameters can be passed to `sentry_sdk.init`.
1 parent 4fb51f2 commit 8a95971

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

sentry_sdk/consts.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import itertools
2+
13
from enum import Enum
24
from sentry_sdk._types import TYPE_CHECKING
35

@@ -479,6 +481,7 @@ class ClientConstructor:
479481
def __init__(
480482
self,
481483
dsn=None, # type: Optional[str]
484+
*,
482485
max_breadcrumbs=DEFAULT_MAX_BREADCRUMBS, # type: int
483486
release=None, # type: Optional[str]
484487
environment=None, # type: Optional[str]
@@ -540,7 +543,7 @@ def __init__(
540543

541544

542545
def _get_default_options():
543-
# type: () -> Dict[str, Any]
546+
# type: () -> dict[str, Any]
544547
import inspect
545548

546549
if hasattr(inspect, "getfullargspec"):
@@ -550,7 +553,14 @@ def _get_default_options():
550553

551554
a = getargspec(ClientConstructor.__init__)
552555
defaults = a.defaults or ()
553-
return dict(zip(a.args[-len(defaults) :], defaults))
556+
kwonlydefaults = a.kwonlydefaults or {}
557+
558+
return dict(
559+
itertools.chain(
560+
zip(a.args[-len(defaults) :], defaults),
561+
kwonlydefaults.items(),
562+
)
563+
)
554564

555565

556566
DEFAULT_OPTIONS = _get_default_options()

sentry_sdk/hub.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _init(*args, **kwargs):
8989
9090
This takes the same arguments as the client constructor.
9191
"""
92-
client = Client(*args, **kwargs) # type: ignore
92+
client = Client(*args, **kwargs)
9393
Scope.get_global_scope().set_client(client)
9494
_check_python_deprecations()
9595
rv = _InitGuard(client)

0 commit comments

Comments
 (0)