Skip to content

Missing return type in lambda_handler_decorator leads to 'Untyped decorator makes function "..." untyped' errors in mypy strict mode #1060

Closed
@huonw

Description

@huonw

What were you trying to accomplish?

I'm trying to use aws_lambda_powertools.utilities.data_classes.event_source with mypy --strict, and receive errors about Untyped decorator makes function "handler" untyped. This is because lambda_handler_decorator is missing a return value, so mypy doesn't know anything about any function decorated with it (including event_source):

https://github.com/awslabs/aws-lambda-powertools-python/blob/22f8b9a7f47a2a4682c6f3f03536ac848ae7dc0d/aws_lambda_powertools/middleware_factory/factory.py#L15

Expected Behavior

@event_source and other decorators using @lambda_handler_decorator should work in mypy strict mode.

Current Behavior

Mypy emits errors.

Possible Solution

  1. Add an appropriate Callable[something, here] return value to lambda_handler_decorator
  2. Run mypy --strict in this package's CI

Steps to Reproduce (for bugs)

requirements:

aws-lambda-powertools==1.25.1
aws-xray-sdk==2.9.0
boto3==1.21.13
botocore==1.24.13
fastjsonschema==2.15.3
future==0.18.2
jmespath==0.10.0
mypy-extensions==0.4.3
mypy==0.931
python-dateutil==2.8.2
s3transfer==0.5.2
six==1.16.0
tomli==2.0.1
typing-extensions==4.1.1
urllib3==1.26.8
wrapt==1.13.3

input.py:

from typing import Any

from aws_lambda_powertools.middleware_factory import lambda_handler_decorator

from aws_lambda_powertools.utilities.data_classes import (
    event_source,
    KinesisStreamEvent,
)


@lambda_handler_decorator
def custom_decorator() -> None:
    return


@event_source(data_class=KinesisStreamEvent)
@custom_decorator
def handler(event: KinesisStreamEvent, context: Any) -> None:
    pass

invocation:

$ mypy --strict input.py 
input.py:16: error: Untyped decorator makes function "handler" untyped
input.py:17: error: Untyped decorator makes function "handler" untyped

Environment

  • Powertools version used: 1.25.1
  • Packaging format (Layers, PyPi): N/A
  • AWS Lambda function runtime: N/A
  • Debugging logs N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions