Skip to content

Commit

Permalink
docs(init): Fix sentry_sdk.init type hint (#3283)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
szokeasaurusrex authored Jul 12, 2024
1 parent 4fb51f2 commit 8a95971
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import itertools

from enum import Enum
from sentry_sdk._types import TYPE_CHECKING

Expand Down Expand Up @@ -479,6 +481,7 @@ class ClientConstructor:
def __init__(
self,
dsn=None, # type: Optional[str]
*,
max_breadcrumbs=DEFAULT_MAX_BREADCRUMBS, # type: int
release=None, # type: Optional[str]
environment=None, # type: Optional[str]
Expand Down Expand Up @@ -540,7 +543,7 @@ def __init__(


def _get_default_options():
# type: () -> Dict[str, Any]
# type: () -> dict[str, Any]
import inspect

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

a = getargspec(ClientConstructor.__init__)
defaults = a.defaults or ()
return dict(zip(a.args[-len(defaults) :], defaults))
kwonlydefaults = a.kwonlydefaults or {}

return dict(
itertools.chain(
zip(a.args[-len(defaults) :], defaults),
kwonlydefaults.items(),
)
)


DEFAULT_OPTIONS = _get_default_options()
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _init(*args, **kwargs):
This takes the same arguments as the client constructor.
"""
client = Client(*args, **kwargs) # type: ignore
client = Client(*args, **kwargs)
Scope.get_global_scope().set_client(client)
_check_python_deprecations()
rv = _InitGuard(client)
Expand Down

0 comments on commit 8a95971

Please sign in to comment.