Skip to content

Commit 053baef

Browse files
ascopesheitorlessa
andauthored
chore(logger): overload inject_lambda_context with generics (#1583)
Co-authored-by: heitorlessa <[email protected]>
1 parent 9f3d748 commit 053baef

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Diff for: aws_lambda_powertools/logging/logger.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
Optional,
1919
TypeVar,
2020
Union,
21+
overload,
2122
)
2223

2324
import jmespath
2425

2526
from ..shared import constants
2627
from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
28+
from ..shared.types import AnyCallableT
2729
from .exceptions import InvalidLoggerSamplingRateError
2830
from .filters import SuppressFilter
2931
from .formatter import (
@@ -314,13 +316,33 @@ def _configure_sampling(self):
314316
f"Please review POWERTOOLS_LOGGER_SAMPLE_RATE environment variable."
315317
)
316318

319+
@overload
317320
def inject_lambda_context(
318321
self,
319-
lambda_handler: Optional[Callable[[Dict, Any], Any]] = None,
322+
lambda_handler: AnyCallableT,
320323
log_event: Optional[bool] = None,
321324
correlation_id_path: Optional[str] = None,
322325
clear_state: Optional[bool] = False,
323-
):
326+
) -> AnyCallableT:
327+
...
328+
329+
@overload
330+
def inject_lambda_context(
331+
self,
332+
lambda_handler: None = None,
333+
log_event: Optional[bool] = None,
334+
correlation_id_path: Optional[str] = None,
335+
clear_state: Optional[bool] = False,
336+
) -> Callable[[AnyCallableT], AnyCallableT]:
337+
...
338+
339+
def inject_lambda_context(
340+
self,
341+
lambda_handler: Optional[AnyCallableT] = None,
342+
log_event: Optional[bool] = None,
343+
correlation_id_path: Optional[str] = None,
344+
clear_state: Optional[bool] = False,
345+
) -> Any:
324346
"""Decorator to capture Lambda contextual info and inject into logger
325347
326348
Parameters

0 commit comments

Comments
 (0)