Skip to content

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

Closed
@rafrafek

Description

@rafrafek

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    loggertypingStatic typing definition related issues (mypy, pyright, etc.)

    Type

    No type

    Projects

    Status

    Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions