Skip to content

Commit

Permalink
fix(logger): fix unknown attributes being ignored by mypy (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayaverdier authored Oct 31, 2022
1 parent 1d6ca2d commit 2798da1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import traceback
from typing import (
IO,
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand Down Expand Up @@ -241,10 +242,14 @@ def __init__(

self._init_logger(formatter_options=formatter_options, **kwargs)

def __getattr__(self, name):
# Proxy attributes not found to actual logger to support backward compatibility
# https://github.com/awslabs/aws-lambda-powertools-python/issues/97
return getattr(self._logger, name)
# Prevent __getattr__ from shielding unknown attribute errors in type checkers
# https://github.com/awslabs/aws-lambda-powertools-python/issues/1660
if not TYPE_CHECKING:

def __getattr__(self, name):
# Proxy attributes not found to actual logger to support backward compatibility
# https://github.com/awslabs/aws-lambda-powertools-python/issues/97
return getattr(self._logger, name)

def _get_logger(self):
"""Returns a Logger named {self.service}, or {self.service.filename} for child loggers"""
Expand Down

0 comments on commit 2798da1

Please sign in to comment.