Skip to content

@logger.inject_lambda_context Type is Partially Unknown #1089

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

Closed
Torsitano opened this issue Apr 1, 2022 · 4 comments
Closed

@logger.inject_lambda_context Type is Partially Unknown #1089

Torsitano opened this issue Apr 1, 2022 · 4 comments
Labels
need-customer-feedback Requires more customers feedback before making or revisiting a decision typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@Torsitano
Copy link

I was attempting to use the @logger.inject_lambda_context decorator as shown in the docs here: https://awslabs.github.io/aws-lambda-powertools-python/latest/core/logger/#capturing-lambda-context-info

Expected Behavior

Decorator does not cause type errors.

Current Behavior

VSCode/Pylance throws an error stating:

Type of "inject_lambda_context" is partially unknown
  Type of "inject_lambda_context" is "(lambda_handler: ((Dict[Unknown, Unknown], Any) -> Any) | None = None, log_event: bool | None = None, correlation_id_path: str | None = None, clear_state: bool | None = False) -> (partial[Unknown] | ((event: Unknown, context: Unknown, **kwargs: Unknown) -> Any))"

Possible Solution

Unknown

Steps to Reproduce (for bugs)

  1. Enable strict type checking with Pylance in VSCode
  2. Create a new .venv using Python 3.9.12
  3. Install PowerTools package
  4. Paste the following code:
from aws_lambda_powertools.logging import Logger
from aws_lambda_powertools.utilities.typing import LambdaContext
from typing import Any

logger = Logger(service = 'test')


@logger.inject_lambda_context
def handler(event: dict[str, Any], context: LambdaContext):

    return {
        'statusCode': 200
    }
  1. Check squiggly red line under @logger.inject_lambda_context

Environment

  • Package versions used:
aws-lambda-powertools==1.25.6
aws-xray-sdk==2.9.0   
boto3==1.21.31        
botocore==1.24.31     
fastjsonschema==2.15.3
future==0.18.2        
jmespath==0.10.0      
python-dateutil==2.8.2
s3transfer==0.5.2     
six==1.16.0
urllib3==1.26.9
wrapt==1.14.0

Pylance VSCode extension version v2022.3.4

  • AWS Lambda function runtime: Python 3.9.12
@Torsitano Torsitano added bug Something isn't working triage Pending triage from maintainers labels Apr 1, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Apr 1, 2022

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@heitorlessa heitorlessa added typing Static typing definition related issues (mypy, pyright, etc.) and removed triage Pending triage from maintainers bug Something isn't working labels Apr 12, 2022
@heitorlessa
Copy link
Contributor

Hi @Torsitano , thank you for opening your first issue and flagging a type def to us!

As of now, we don't support strict mode within type checkers - both Mypy and Pyright (your case). When trying so, we found quite difficult to keep the code maintainable as well as ensure 100% accuracy due to heavy use of metaprogramming (plus supporting older versions of Python that don't yet have certain mechanisms).

I'm changing the label from bug to static_typing. We welcome any targeted solution to this specific type def that also works for 3.6+ as well as Mypy.

Thank you!

@heitorlessa heitorlessa added the need-customer-feedback Requires more customers feedback before making or revisiting a decision label Apr 12, 2022
@Torsitano
Copy link
Author

@heitorlessa Hey, thanks for the response, I appreciate the context. Understand on the difficulty getting this to work for multiple versions, so that makes sense.

@mew1033
Copy link
Contributor

mew1033 commented Mar 7, 2023

I was updating some old code and got a Unnecessary "# type: ignore" comment error. Looks like this decorator is now fully supported with strict typing. Sweet! Thanks all!
@Torsitano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-customer-feedback Requires more customers feedback before making or revisiting a decision typing Static typing definition related issues (mypy, pyright, etc.)
Projects
None yet
Development

No branches or pull requests

3 participants