Skip to content

Commit 76f3a32

Browse files
committed
fix: addressing comments
1 parent 526d9f7 commit 76f3a32

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
cast,
2727
)
2828

29-
from typing_extensions import Literal
30-
3129
from aws_lambda_powertools.event_handler import content_types
3230
from aws_lambda_powertools.event_handler.exceptions import NotFoundError, ServiceError
3331
from aws_lambda_powertools.event_handler.openapi.types import (
@@ -39,6 +37,7 @@
3937
from aws_lambda_powertools.shared.cookies import Cookie
4038
from aws_lambda_powertools.shared.functions import powertools_dev_is_set
4139
from aws_lambda_powertools.shared.json_encoder import Encoder
40+
from aws_lambda_powertools.shared.types import Literal
4241
from aws_lambda_powertools.utilities.data_classes import (
4342
ALBEvent,
4443
APIGatewayProxyEvent,

aws_lambda_powertools/event_handler/openapi/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from typing import Any, Dict, List, Optional, Set, Union
33

44
from pydantic import AnyUrl, BaseModel, Field
5-
from typing_extensions import Annotated, Literal
65

76
from aws_lambda_powertools.event_handler.openapi.compat import model_rebuild
87
from aws_lambda_powertools.event_handler.openapi.types import PYDANTIC_V2
8+
from aws_lambda_powertools.shared.types import Annotated, Literal
99

1010
"""
1111
The code defines Pydantic models for the various OpenAPI objects like OpenAPI, PathItem, Operation, Parameter etc.

aws_lambda_powertools/event_handler/openapi/params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from pydantic import BaseConfig
66
from pydantic.fields import FieldInfo
7-
from typing_extensions import Annotated, Literal, get_args, get_origin
87

98
from aws_lambda_powertools.event_handler.openapi.compat import (
109
ModelField,
@@ -16,6 +15,7 @@
1615
get_annotation_from_field_info,
1716
)
1817
from aws_lambda_powertools.event_handler.openapi.types import PYDANTIC_V2, CacheKey
18+
from aws_lambda_powertools.shared.types import Annotated, Literal, get_args, get_origin
1919

2020
"""
2121
This turns the low-level function signature into typed, validated Pydantic models for consumption.

aws_lambda_powertools/shared/types.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22
from typing import Any, Callable, Dict, List, TypeVar, Union
33

44
if sys.version_info >= (3, 8):
5-
from typing import Literal, Protocol, TypedDict
5+
from typing import Literal, Protocol, TypedDict, get_args
66
else:
7-
from typing_extensions import Literal, Protocol, TypedDict
7+
from typing_extensions import Literal, Protocol, TypedDict, get_args
88

9+
if sys.version_info >= (3, 9):
10+
from typing import Annotated
11+
else:
12+
from typing_extensions import Annotated
913

1014
if sys.version_info >= (3, 11):
1115
from typing import NotRequired
1216
else:
1317
from typing_extensions import NotRequired
1418

1519

20+
# Even though `get_origin` was added in Python 3.8, it only handles Annotated correctly on 3.10.
21+
# So for python < 3.10 we use the backport from typing_extensions.
1622
if sys.version_info >= (3, 10):
17-
from typing import TypeAlias
23+
from typing import TypeAlias, get_origin
1824
else:
19-
from typing_extensions import TypeAlias
25+
from typing_extensions import TypeAlias, get_origin
2026

2127
AnyCallableT = TypeVar("AnyCallableT", bound=Callable[..., Any]) # noqa: VNE001
2228
# JSON primitives only, mypy doesn't support recursive tho
2329
JSONType = Union[str, int, float, bool, None, Dict[str, Any], List[Any]]
2430

25-
__all__ = ["Protocol", "TypedDict", "Literal", "NotRequired", "TypeAlias"]
31+
__all__ = ["get_args", "get_origin", "Annotated", "Protocol", "TypedDict", "Literal", "NotRequired", "TypeAlias"]

tests/functional/event_handler/test_openapi_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import List
44

55
from pydantic import BaseModel
6-
from typing_extensions import Annotated
76

87
from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver
98
from aws_lambda_powertools.event_handler.openapi.models import (
@@ -13,6 +12,7 @@
1312
Schema,
1413
)
1514
from aws_lambda_powertools.event_handler.openapi.params import Body, Query
15+
from aws_lambda_powertools.shared.types import Annotated
1616

1717
JSON_CONTENT_TYPE = "application/json"
1818

tests/functional/event_handler/test_openapi_validation_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import json
22

33
from pydantic import BaseModel
4-
from typing_extensions import Annotated
54

65
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
76
from aws_lambda_powertools.event_handler.openapi.params import Body
7+
from aws_lambda_powertools.shared.types import Annotated
88
from tests.functional.utils import load_event
99

1010
LOAD_GW_EVENT = load_event("apiGatewayProxyEvent.json")

0 commit comments

Comments
 (0)