Skip to content
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

Static typing: Logger.exception() exc_info type does not match Python's built-in one #3356

Closed
rafrafek opened this issue Nov 17, 2023 · 8 comments
Labels
logger typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@rafrafek
Copy link
Contributor

rafrafek commented Nov 17, 2023

Static type checker used

pyright/pylance

AWS Lambda function runtime

3.11

Powertools for AWS Lambda (Python) version

latest

Static type checker info

Pyright 1.1.331

Code snippet

from aws_lambda_powertools.logging import Logger
logger = Logger(name="%(name)s")
...
ex = Exception()
logger.exception(
    f"Failed to launch workflow: {ex!r}",
    extra=None,
    exc_info=(type(ex), ex, ex.__traceback__),
)

Possible Solution

exc_info should not be bool only, it should be:
"_ExcInfoType" which accepts:

"None"
"bool"
"tuple[type[BaseException], BaseException, TracebackType | None]"
"tuple[None, None, None]"
"BaseException"

@rafrafek rafrafek added triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.) labels Nov 17, 2023
Copy link

boring-cyborg bot commented Nov 17, 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

@rafrafek
Copy link
Contributor Author

Workaround:

Use logger._logger.exception() instead of logger.exception() to satisfy the static type checker.

@heitorlessa heitorlessa added logger and removed triage Pending triage from maintainers labels Nov 21, 2023
@heitorlessa heitorlessa moved this from Triage to Working on it in Powertools for AWS Lambda (Python) Nov 21, 2023
@heitorlessa
Copy link
Contributor

hey @rafrafek thanks for spotting yet another one - we must have missed during the review (it was workaround override for the lack of stackframe in 3.8 only in logging.Logger).

Tackling that shortly

@heitorlessa
Copy link
Contributor

I see why this was copied as-is from CPython logging impl: https://github.com/python/cpython/blob/d67f947c72af8a215db2fd285e5de9b1e671fde1/Lib/logging/__init__.py#L1537

@heitorlessa
Copy link
Contributor

Waiting for CI to confirm it won't break previous versions, as I'm unsure when CPython added that typing alias since the exception() implementation don't have it either.

@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2023
@heitorlessa
Copy link
Contributor

Closing, coming up in the next release. Thank you one more time @rafrafek for reporting it!

@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Nov 21, 2023
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.

Copy link
Contributor

This is now released under 2.27.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2023
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Dec 6, 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

No branches or pull requests

2 participants