8000 mypy fails with @tracer.capture_lambda_handler · Issue #360 · aws-powertools/powertools-lambda-python · GitHub
[go: up one dir, main page]

Skip to content
mypy fails with @tracer.capture_lambda_handler #360
Closed
@joyofhex

Description

@joyofhex

Using mypy to typecheck code decorated with the @tracer.capture_lambda_handler fails since v1.10.

Expected Behavior

Mypy should not fail with code decorated with the capture_lambda_handler.

Current Behavior

❯ poetry run mypy src
src/handler.py:5: error: Argument 1 to "capture_lambda_handler" of "Tracer" has incompatible type "Callable[[Any, Any], Any]"; expected "Optional[Callable[[Dict[Any, Any], Any, Optional[Dict[Any, Any]]], Any]]"
Found 1 error in 1 file (checked 1 source file)

Possible Solution

First of all, thanks for the incredibly useful library. It has been a pleasure to work with it.

It seems that in commit 11ebcf9 the following change was introduced:

@@ -238,7 +242,7 @@ class Tracer:

     def capture_lambda_handler(
         self,
-        lambda_handler: Callable[[Dict, Any], Any] = None,
+        lambda_handler: Callable[[Dict, Any, Optional[Dict]], Any] = None,
         capture_response: Optional[bool] = None,
         capture_error: Optional[bool] = None,
     ):

This seems to have changed the expected handler signature to have three parameters instead of two, which is causing the sample code to fail. I've worked around this for now by adding a _ignored: Optional[Any] = None parameter to my lambda handler.

Steps to Reproduce (for bugs)

I created a small repo repo (uh) here: https://github.com/joyofhex/repocase-for-powertools

  1. clone above repo
  2. cd into repo
  3. poetry run mypy

Environment

  • Powertools version used: 1.13.0
  • Packaging format (Layers, PyPi): pypi
  • AWS Lambda function runtime: python 3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0