Skip to content

Typing issue #2460

Closed
Closed
@agusdmb

Description

@agusdmb

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.32.0

Steps to Reproduce

In the following snippet i am changing a super signature with a subclass, using mypy or any other static type checker this is mark as an error, but when the sentry decorator is added (as in the example) the error is hidden.

import sentry_sdk


class A:
    def foo(self, bar: int) -> int:
        return bar


class B(A):
    @sentry_sdk.trace
    def foo(self, bar: str) -> str:
        return bar

The issue is in the following lines:

def trace(func=None):
# type: (Any) -> Any

the decorator is changing the signature of both input and output to Any. This is not the expected behavior since the function will not actually be changed. And because the original signature expects integers, but the overriden one expects strings (which are not compatible) but when type checking the checker all it sees is "any" then because int is part of any is not giving any error when it should.

This can be easily fix by using a TypeVar in this case, like so:

from typing import TypeVar

T = TypeVar("T")

def trace(func=None):
    # type: (T) -> T

Expected Result

Type checker (like mypy) complains that the signature is not correct

Actual Result

Type checker (like mypy) doesn't complain at all, the bug is hidden

Metadata

Metadata

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions