Skip to content

Some code structures are not conducive to static typing #386

Description

@bluetech

This package now declares that it includes typings so I tried to whitelist it in one of my projects. Unfortunately I got various errors like error: Module has no attribute "push_scope" for sentry_sdk.push_scope().

I haven't tried it but I suspect that dynamic code structures like

__all__ = api_all + [ # noqa
"Hub",
"Scope",
"Client",
"Transport",
"HttpTransport",
"init",
"integrations",
]

def public(f):
__all__.append(f.__name__)
return f
def hubmethod(f):
f.__doc__ = "%s\n\n%s" % (
"Alias for `Hub.%s`" % f.__name__,
inspect.getdoc(getattr(Hub, f.__name__)),
)
return public(f)
@hubmethod
def capture_event(event, hint=None):
# type: (Dict[str, Any], Dict[str, Any]) -> Optional[str]
hub = Hub.current
if hub is not None:
return hub.capture_event(event, hint)
return None
@hubmethod
def capture_message(message, level=None):
# type: (str, Optional[Any]) -> Optional[str]
hub = Hub.current
if hub is not None:
return hub.capture_message(message, level)
return None

are too hard for mypy to understand. I was wondering if you'd be willing to forgo these (nice) shortcuts in order to help mypy. I'll be happy to send a PR if so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions