Skip to content

Commit 2798da1

Browse files
authored
fix(logger): fix unknown attributes being ignored by mypy (#1670)
1 parent 1d6ca2d commit 2798da1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

aws_lambda_powertools/logging/logger.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import traceback
99
from typing import (
1010
IO,
11+
TYPE_CHECKING,
1112
Any,
1213
Callable,
1314
Dict,
@@ -241,10 +242,14 @@ def __init__(
241242

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

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

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

0 commit comments

Comments
 (0)