Skip to content

Commit 68e0c7e

Browse files
docs(init): Fix sentry_sdk.init type hint
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 68e0c7e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sentry_sdk/consts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class ClientConstructor:
479479
def __init__(
480480
self,
481481
dsn=None, # type: Optional[str]
482+
*,
482483
max_breadcrumbs=DEFAULT_MAX_BREADCRUMBS, # type: int
483484
release=None, # type: Optional[str]
484485
environment=None, # type: Optional[str]
@@ -540,7 +541,7 @@ def __init__(
540541

541542

542543
def _get_default_options():
543-
# type: () -> Dict[str, Any]
544+
# type: () -> dict[str, Any]
544545
import inspect
545546

546547
if hasattr(inspect, "getfullargspec"):
@@ -549,8 +550,11 @@ def _get_default_options():
549550
getargspec = inspect.getargspec # type: ignore
550551

551552
a = getargspec(ClientConstructor.__init__)
552-
defaults = a.defaults or ()
553-
return dict(zip(a.args[-len(defaults) :], defaults))
553+
554+
# The logic below relies on all parameters having a default value.
555+
# We would need to update the behavior if we ever introduce an
556+
# argument without a default value.
557+
return dict(a.defaults.items() | a.kwonlydefaults.items())
554558

555559

556560
DEFAULT_OPTIONS = _get_default_options()

0 commit comments

Comments
 (0)