sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Type definition for @serverless_function seems wrong

Open rm-hull opened this issue 3 years ago • 1 comments

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.9.10

Steps to Reproduce

Annotating a function with @serverless_function, eg:

@serverless_function
def main(msg: func.QueueMessage) -> None:
    ...

This gives a type signature of main: ((msg: QueueMessage) -> None) | (((msg: QueueMessage) -> None) -> ((msg: QueueMessage) -> None)). I cant quite fathom why this is like this. Looking at https://github.com/getsentry/sentry-python/blame/master/sentry_sdk/integrations/serverless.py#L42, the type signature is declared as:

# type: (Optional[F], bool) -> Union[F, Callable[[F], F]]

If I remove the decorator, then the type signature is simply main: (msg: QueueMessage) -> None) which is what I would expect the decorated function to also return.

Can you explain why the decorator type definition cannot just simply return the type of the wrapped function?, as per:

# type: (Optional[F], bool) -> F

Expected Result

pylance does not mark all my annotated handlers in a sea of type errors

Actual Result

pylance marks all my code in a sea of type errors

rm-hull avatar Oct 04 '22 16:10 rm-hull

there's a couple of @overload's above that definition, so this should work out correctly? If Optional[F] is None, we can't have the return type to be F, it's the other Callable thingy.

sl0thentr0py avatar Oct 05 '22 14:10 sl0thentr0py

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Oct 27 '22 00:10 github-actions[bot]