generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 462
Closed
Labels
typingStatic typing definition related issues (mypy, pyright, etc.)Static typing definition related issues (mypy, pyright, etc.)
Description
What were you trying to accomplish?
Check code that uses aws_lambda_powertools using pyright.
Expected Behavior
Checking code that correctly uses aws_lambda_powertools should be successful.
Current Behavior
Checking code that uses the event_source decorator as documented fails with:
lambda_function.py
lambda_function.py:6:15 - error: No parameter named "data_class" (reportGeneralTypeIssues)
lambda_function.py:6:2 - error: Argument missing for parameter "context" (reportGeneralTypeIssues)
Here's the code used:
import json
from aws_lambda_powertools.utilities.data_classes import event_source, APIGatewayProxyEventV2
@event_source(data_class=APIGatewayProxyEventV2)
def lambda_handler(event: APIGatewayProxyEventV2, context):
return {
"statusCode": 200,
"body": json.dumps({"message": f"hello {event.json_body['name']}!"})
}Other types might be affected too. Here's the output when pyright with the special option "--verifytypes" is called on aws_lambda_powertools:
Symbols exported by "aws_lambda_powertools": 2095
With known type: 1733
With ambiguous type: 77
With unknown type: 285
Type completeness score: 82.7%
This means about 17% of the symbols exposed are not properly annotated.
See this comment here.
Possible Solution
Complete the type annotations.
Steps to Reproduce (for bugs)
❯ python3 -m venv venv
❯ . venv/bin/activate
❯ pip install aws_lambda_powertools pyright
❯ mkdir src
❯ >>! src/lambda_function.py <<\EOF
import json
from aws_lambda_powertools.utilities.data_classes import event_source, APIGatewayProxyEventV2
@event_source(data_class=APIGatewayProxyEventV2)
def lambda_handler(event: APIGatewayProxyEventV2, context):
return {
"statusCode": 200,
"body": json.dumps({"message": f"hello {event.json_body['name']}!"})
}
EOF
❯ >>! pyproject.toml <<\EOF
[tool.pyright]
pythonPlatform = "Linux"
pythonVersion = "3.9"
stubPath = ""
executionEnvironments = [
{root = "src"},
]
EOF
❯ pyright
No configuration file found.
pyproject.toml file found at /tmp/test.
Loading pyproject.toml file at /tmp/test/pyproject.toml
No include entries specified; assuming /tmp/test
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
Searching for source files
Auto-excluding /tmp/test/venv
Found 1 source file
/tmp/test/src/lambda_function.py
/tmp/test/src/lambda_function.py:6:15 - error: No parameter named "data_class" (reportGeneralTypeIssues)
/tmp/test/src/lambda_function.py:6:2 - error: Argument missing for parameter "context" (reportGeneralTypeIssues)
2 errors, 0 warnings, 0 informations
Completed in 0.767sec
Environment
- Powertools version used: 1.25.5
- Packaging format (Layers, PyPi): N/A
- AWS Lambda function runtime: N/A
- Debugging logs
N/A
gshpychka, kjones and ariasvzlamichaelbrewer
Metadata
Metadata
Assignees
Labels
typingStatic typing definition related issues (mypy, pyright, etc.)Static typing definition related issues (mypy, pyright, etc.)