Skip to content

Commit 12aeb50

Browse files
refactor(event_handlers): remove unnecessary init methods (#8127)
refactor: remove init methods
1 parent 8b42829 commit 12aeb50

File tree

3 files changed

+18
-128
lines changed

3 files changed

+18
-128
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,11 @@ def lambda_handler(event, context):
14601460
```
14611461
"""
14621462

1463+
_proxy_event_type: Enum = ProxyEventType.APIGatewayProxyEvent
1464+
14631465
def __init__(
14641466
self,
1465-
proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent,
1467+
proxy_type: Enum | None = None,
14661468
cors: CORSConfig | None = None,
14671469
debug: bool | None = None,
14681470
serializer: Callable[[dict], str] | None = None,
@@ -1495,7 +1497,7 @@ def __init__(
14951497
function to deserialize `str`, `bytes`, `bytearray` containing a JSON document to a Python `dict`,
14961498
by default json.loads when integrating with EventSource data class
14971499
"""
1498-
self._proxy_type = proxy_type
1500+
self._proxy_type = proxy_type or self._proxy_event_type
14991501
self._dynamic_routes: list[Route] = []
15001502
self._static_routes: list[Route] = []
15011503
self._route_keys: list[str] = []
@@ -2935,28 +2937,7 @@ class APIGatewayRestResolver(ApiGatewayResolver):
29352937
"""Amazon API Gateway REST and HTTP API v1 payload resolver"""
29362938

29372939
current_event: APIGatewayProxyEvent
2938-
2939-
def __init__(
2940-
self,
2941-
cors: CORSConfig | None = None,
2942-
debug: bool | None = None,
2943-
serializer: Callable[[dict], str] | None = None,
2944-
strip_prefixes: list[str | Pattern] | None = None,
2945-
enable_validation: bool = False,
2946-
response_validation_error_http_code: HTTPStatus | int | None = None,
2947-
json_body_deserializer: Callable[[str], dict] | None = None,
2948-
):
2949-
"""Amazon API Gateway REST and HTTP API v1 payload resolver"""
2950-
super().__init__(
2951-
ProxyEventType.APIGatewayProxyEvent,
2952-
cors,
2953-
debug,
2954-
serializer,
2955-
strip_prefixes,
2956-
enable_validation,
2957-
response_validation_error_http_code,
2958-
json_body_deserializer=json_body_deserializer,
2959-
)
2940+
_proxy_event_type = ProxyEventType.APIGatewayProxyEvent
29602941

29612942
def _get_base_path(self) -> str:
29622943
# 3 different scenarios:
@@ -3025,28 +3006,7 @@ class APIGatewayHttpResolver(ApiGatewayResolver):
30253006
"""Amazon API Gateway HTTP API v2 payload resolver"""
30263007

30273008
current_event: APIGatewayProxyEventV2
3028-
3029-
def __init__(
3030-
self,
3031-
cors: CORSConfig | None = None,
3032-
debug: bool | None = None,
3033-
serializer: Callable[[dict], str] | None = None,
3034-
strip_prefixes: list[str | Pattern] | None = None,
3035-
enable_validation: bool = False,
3036-
response_validation_error_http_code: HTTPStatus | int | None = None,
3037-
json_body_deserializer: Callable[[str], dict] | None = None,
3038-
):
3039-
"""Amazon API Gateway HTTP API v2 payload resolver"""
3040-
super().__init__(
3041-
ProxyEventType.APIGatewayProxyEventV2,
3042-
cors,
3043-
debug,
3044-
serializer,
3045-
strip_prefixes,
3046-
enable_validation,
3047-
response_validation_error_http_code,
3048-
json_body_deserializer=json_body_deserializer,
3049-
)
3009+
_proxy_event_type = ProxyEventType.APIGatewayProxyEventV2
30503010

30513011
def _get_base_path(self) -> str:
30523012
# 3 different scenarios:
@@ -3066,6 +3026,7 @@ class ALBResolver(ApiGatewayResolver):
30663026
"""Amazon Application Load Balancer (ALB) resolver"""
30673027

30683028
current_event: ALBEvent
3029+
_proxy_event_type = ProxyEventType.ALBEvent
30693030

30703031
def __init__(
30713032
self,
@@ -3105,13 +3066,12 @@ def __init__(
31053066
Enables URL-decoding of query parameters (both keys and values), by default False.
31063067
"""
31073068
super().__init__(
3108-
ProxyEventType.ALBEvent,
3109-
cors,
3110-
debug,
3111-
serializer,
3112-
strip_prefixes,
3113-
enable_validation,
3114-
response_validation_error_http_code,
3069+
cors=cors,
3070+
debug=debug,
3071+
serializer=serializer,
3072+
strip_prefixes=strip_prefixes,
3073+
enable_validation=enable_validation,
3074+
response_validation_error_http_code=response_validation_error_http_code,
31153075
json_body_deserializer=json_body_deserializer,
31163076
)
31173077
self.decode_query_parameters = decode_query_parameters

aws_lambda_powertools/event_handler/lambda_function_url.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Pattern
3+
from typing import TYPE_CHECKING
44

55
from aws_lambda_powertools.event_handler.api_gateway import (
66
ApiGatewayResolver,
77
ProxyEventType,
88
)
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Callable
12-
from http import HTTPStatus
13-
14-
from aws_lambda_powertools.event_handler import CORSConfig
1511
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
1612

1713

@@ -52,27 +48,7 @@ def lambda_handler(event, context):
5248
"""
5349

5450
current_event: LambdaFunctionUrlEvent
55-
56-
def __init__(
57-
self,
58-
cors: CORSConfig | None = None,
59-
debug: bool | None = None,
60-
serializer: Callable[[dict], str] | None = None,
61-
strip_prefixes: list[str | Pattern] | None = None,
62-
enable_validation: bool = False,
63-
response_validation_error_http_code: HTTPStatus | int | None = None,
64-
json_body_deserializer: Callable[[str], dict] | None = None,
65-
):
66-
super().__init__(
67-
ProxyEventType.LambdaFunctionUrlEvent,
68-
cors,
69-
debug,
70-
serializer,
71-
strip_prefixes,
72-
enable_validation,
73-
response_validation_error_http_code,
74-
json_body_deserializer=json_body_deserializer,
75-
)
51+
_proxy_event_type = ProxyEventType.LambdaFunctionUrlEvent
7652

7753
def _get_base_path(self) -> str:
7854
stage = self.current_event.request_context.stage

aws_lambda_powertools/event_handler/vpc_lattice.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Pattern
3+
from typing import TYPE_CHECKING
44

55
from aws_lambda_powertools.event_handler.api_gateway import (
66
ApiGatewayResolver,
77
ProxyEventType,
88
)
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Callable
12-
from http import HTTPStatus
13-
14-
from aws_lambda_powertools.event_handler import CORSConfig
1511
from aws_lambda_powertools.utilities.data_classes import VPCLatticeEvent, VPCLatticeEventV2
1612

1713

@@ -48,28 +44,7 @@ def lambda_handler(event, context):
4844
"""
4945

5046
current_event: VPCLatticeEvent
51-
52-
def __init__(
53-
self,
54-
cors: CORSConfig | None = None,
55-
debug: bool | None = None,
56-
serializer: Callable[[dict], str] | None = None,
57-
strip_prefixes: list[str | Pattern] | None = None,
58-
enable_validation: bool = False,
59-
response_validation_error_http_code: HTTPStatus | int | None = None,
60-
json_body_deserializer: Callable[[str], dict] | None = None,
61-
):
62-
"""Amazon VPC Lattice resolver"""
63-
super().__init__(
64-
ProxyEventType.VPCLatticeEvent,
65-
cors,
66-
debug,
67-
serializer,
68-
strip_prefixes,
69-
enable_validation,
70-
response_validation_error_http_code,
71-
json_body_deserializer=json_body_deserializer,
72-
)
47+
_proxy_event_type = ProxyEventType.VPCLatticeEvent
7348

7449
def _get_base_path(self) -> str:
7550
return ""
@@ -108,28 +83,7 @@ def lambda_handler(event, context):
10883
"""
10984

11085
current_event: VPCLatticeEventV2
111-
112-
def __init__(
113-
self,
114-
cors: CORSConfig | None = None,
115-
debug: bool | None = None,
116-
serializer: Callable[[dict], str] | None = None,
117-
strip_prefixes: list[str | Pattern] | None = None,
118-
enable_validation: bool = False,
119-
response_validation_error_http_code: HTTPStatus | int | None = None,
120-
json_body_deserializer: Callable[[str], dict] | None = None,
121-
):
122-
"""Amazon VPC Lattice resolver"""
123-
super().__init__(
124-
ProxyEventType.VPCLatticeEventV2,
125-
cors,
126-
debug,
127-
serializer,
128-
strip_prefixes,
129-
enable_validation,
130-
response_validation_error_http_code,
131-
json_body_deserializer=json_body_deserializer,
132-
)
86+
_proxy_event_type = ProxyEventType.VPCLatticeEventV2
13387

13488
def _get_base_path(self) -> str:
13589
return ""

0 commit comments

Comments
 (0)