Skip to content

Static typing: Logger __getattr__ definition causes mypy to not error when missing an attribute #1660

Closed
@nayaverdier

Description

@nayaverdier

Static type checker used

mypy (project's standard)

AWS Lambda function runtime

3.9

AWS Lambda Powertools for Python version

latest

Static type checker info

The issue here is a lack of output. Running mypy with no arguments on the file below does not produce any issues.

Code snippet

from aws_lambda_powertools import Logger

Logger().foobar()

Possible Solution

Based on python/mypy#13319, the preferred solution seems to be the following:

from typing import TYPE_CHECKING

class Logger(logging.Logger):
    ...
    if not TYPE_CHECKING:
        def __getattr__(self, name):
            ...

This appears to resolve the issue on my machine.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions