Skip to content

Tracer.capture_method decorator does not preserve function type hints #465

Closed
@zlalvani

Description

@zlalvani

What were you trying to accomplish?
I want to use the @tracer.capture_method decorator for detailed function level tracing however it's currently unusable because it disables all errors when linting with mypy.

Expected Behavior

See code example below

Current Behavior

Function signatures (argument and return types) are not preserved when decorated with @tracer.capture_method and linting with mypy.

Possible Solution

Mypy can be forced to look at the decorated function signature: https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators

Steps to Reproduce (for bugs)

  1. Use code sample below
  2. Run mypy (tested on mypy==0.782)

Environment

  • Powertools version used: aws-lambda-powertools==1.10.2
  • Packaging format (Layers, PyPi): PyPi

How to enable debug mode**

tracer = Tracer()

@tracer.capture_method
def foo(bar: str) -> str:
    return bar

x = foo('baz')
x.get('this is not a dict')  # should cause mypy error
y = foo(123)  # should cause mypy error

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions