Skip to content

refactor(middleware_factory): add from __future__ import annotations #4941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions aws_lambda_powertools/middleware_factory/factory.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from __future__ import annotations

import functools
import inspect
import logging
import os
from typing import Any, Callable, Optional
from typing import Any, Callable

from ..shared import constants
from ..shared.functions import resolve_truthy_env_var_choice
from ..tracing import Tracer
from .exceptions import MiddlewareInvalidArgumentError
from aws_lambda_powertools.middleware_factory.exceptions import MiddlewareInvalidArgumentError
from aws_lambda_powertools.shared import constants
from aws_lambda_powertools.shared.functions import resolve_truthy_env_var_choice
from aws_lambda_powertools.tracing import Tracer

logger = logging.getLogger(__name__)


# Maintenance: we can't yet provide an accurate return type without ParamSpec etc. see #1066
def lambda_handler_decorator(decorator: Optional[Callable] = None, trace_execution: Optional[bool] = None) -> Callable:
def lambda_handler_decorator(decorator: Callable | None = None, trace_execution: bool | None = None) -> Callable:
"""Decorator factory for decorating Lambda handlers.

You can use lambda_handler_decorator to create your own middlewares,
Expand Down Expand Up @@ -112,7 +114,7 @@ def lambda_handler(event, context):
)

@functools.wraps(decorator)
def final_decorator(func: Optional[Callable] = None, **kwargs: Any):
def final_decorator(func: Callable | None = None, **kwargs: Any):
# If called with kwargs return new func with kwargs
if func is None:
return functools.partial(final_decorator, **kwargs)
Expand Down
Loading