Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for type hints on decorators #767

Open
whwright opened this issue Feb 10, 2023 · 2 comments
Open

Support for type hints on decorators #767

whwright opened this issue Feb 10, 2023 · 2 comments
Labels

Comments

@whwright
Copy link

whwright commented Feb 10, 2023

Is your feature request related to a problem? Please describe.

Usage of decorators such as @newrelic.agent.function_trace prevent mypy from checking types on those functions. Here is mypy documentation describing this issue: https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators

For example

import newrelic.agent

@newrelic.agent.function_trace()
def func_i_want_to_trace(value: str) -> bool:
    return value == "yes"

func_i_want_to_trace(1)

mypy will not catch this type mismatch

Feature Description

Type all newrelic.agent decorators as described in the mypy doc

Describe Alternatives

Here is a workaround

F = TypeVar("F", bound=Callable[..., Any])

def newrelic_agent_function_trace(func: F) -> F:
    return cast(F, newrelic.agent.function_trace()(func))

@newrelic_agent_function_trace
def func_i_want_to_trace(value: str) -> bool:
    return value == "yes"

Additional context

I am not sure if this is possible if you would like to keep supporting python 2.7

Priority

Nice to Have

@TimPansino
Copy link
Contributor

Hello,

The agent uses the wrapt library internally to implement all wrappers, if the signature of functions is being obstructed that would need to be directed to the wrapt library as an issue.

It sounds like this issue has already been raised unless I'm mistaken and there's not been much progress as of yet.

@stale
Copy link

stale bot commented May 22, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants