Is your feature request related to a problem? Please describe.
When I annotate a method with, for example, @capture_span, the method loses its type hints and becomes just a Callable.
For example, Pylance gives the following information tooltips (as commented to the right of the reveal_type calls):
import elasticapm as apm
from typing_extensions import reveal_type
def test (a: int, b: str, c: float) -> bytes:
return b"abc"
@apm.capture_span()
def test_with_apm (a: int, b: str, c: float) -> bytes:
return b"abc"
reveal_type(test) # Type of "test" is "(a: int, b: str, c: float) -> bytes"
reveal_type(test_with_apm) # Type of "test_with_apm" is "(...) -> Any"
Describe the solution you'd like
Just use TypeVar on the __call__ method signature of annotation methods, example:
from typing import TypeVar
_AnnotatedFunctionT = TypeVar("_AnnotatedFunctionT")
class capture_span(object):
...
def __call__(self, func: _AnnotatedFunctionT) -> _AnnotatedFunctionT:
self.name = self.name or get_name_from_func(func)
@functools.wraps(func)
def decorated(*args, **kwds):
with self:
return func(*args, **kwds)
return decorated
...
After this small change, the reveal_type reports the expected type:
import elasticapm as apm
from typing_extensions import reveal_type
@apm.capture_span()
def test_with_apm (a: int, b: str, c: float) -> bytes:
return b"abc"
reveal_type(test_with_apm) # Type of "test_with_apm" is "(a: int, b: str, c: float) -> bytes"
Describe alternatives you've considered
I've considered creating a pull request myself to solve this, but the CONTRIBUTING.md file indicates that an issue should be opened first.
Additional context
Screenshot of VSCode's pylance type hints without the change:

Screenshot of VSCode's pylance type hints with the change:

Is your feature request related to a problem? Please describe.
When I annotate a method with, for example,
@capture_span, the method loses its type hints and becomes just aCallable.For example,
Pylancegives the following information tooltips (as commented to the right of thereveal_typecalls):Describe the solution you'd like
Just use
TypeVaron the__call__method signature of annotation methods, example:After this small change, the
reveal_typereports the expected type:Describe alternatives you've considered
I've considered creating a pull request myself to solve this, but the
CONTRIBUTING.mdfile indicates that an issue should be opened first.Additional context

Screenshot of VSCode's pylance type hints without the change:
Screenshot of VSCode's pylance type hints with the change:
