Skip to content

Static typing: logger.append_keys produces a [no-untyped-call] mypy error #3112

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
FollowTheProcess opened this issue Sep 20, 2023 · 5 comments · Fixed by #3113
Closed

Static typing: logger.append_keys produces a [no-untyped-call] mypy error #3112

FollowTheProcess opened this issue Sep 20, 2023 · 5 comments · Fixed by #3113
Labels
logger typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@FollowTheProcess
Copy link
Contributor

FollowTheProcess commented Sep 20, 2023

Static type checker used

mypy (project's standard)

AWS Lambda function runtime

3.10

Powertools for AWS Lambda (Python) version

latest

Static type checker info

Output

error: Call to untyped function "append_keys" in typed context  [no-untyped-call]
        logger.append_keys(something="yes please")
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Config

# pyproject.toml
[tool.mypy]
files = [ "**/*.py" ]
ignore_missing_imports = true
strict = true
pretty = true
show_error_codes = true
warn_unreachable = true
enable_error_code = [ "ignore-without-code", "redundant-expr", "truthy-bool" ]
plugins = [ "pydantic.mypy" ]

Run

I just run mypy on the command line from within the virtual environment

Code snippet

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from aws_lambda_powertools import Logger

if TYPE_CHECKING:
    from aws_lambda_powertools.utilities.typing import LambdaContext


logger = Logger(utc=True)


def lambda_handler(event: dict[str, Any], context: LambdaContext) -> dict[str, Any]:
    logger.append_keys(something="yes please") # Error here
    return {"hello": "world"}

Possible Solution

It seems that in a few places in powertools where a function or method would return None, the return type annotation is omitted. One such example is append_keys

def append_keys(self, **additional_keys):

The solution would be to simply add -> None: as the return type annotation 🙂, preferably in other places where it's missing too.

Happy to do a PR for this, just waiting for triage 👍🏻

@FollowTheProcess FollowTheProcess added triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.) labels Sep 20, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 20, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@heitorlessa heitorlessa added logger and removed triage Pending triage from maintainers labels Sep 20, 2023
@heitorlessa
Copy link
Contributor

Hey @FollowTheProcess please feel free to send a PR 🥹

Thank you for taking the time to fill in such a great static typing issue -- we will definitely use this as a great example to follow ;)

We're at events this week hence small delays in our usual response/triaging.

Thank you!!

@FollowTheProcess
Copy link
Contributor Author

Great! Done a first pass in #3113, surfaced a few questions though 🙂

@heitorlessa heitorlessa linked a pull request Sep 20, 2023 that will close this issue
7 tasks
@github-project-automation github-project-automation bot moved this from Triage to Coming soon in Powertools for AWS Lambda (Python) Sep 22, 2023
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Sep 22, 2023
@github-actions
Copy link
Contributor

This is now released under 2.25.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Sep 22, 2023
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logger typing Static typing definition related issues (mypy, pyright, etc.)
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

2 participants