From 2591050fe55e8133967458f9c6a55e6d45388507 Mon Sep 17 00:00:00 2001 From: nadobando Date: Thu, 4 Feb 2021 10:30:47 +0200 Subject: [PATCH] fix: remove unnecessary typing-extensions for py3.8 (#281) * fix: remove unnecessary typing-extensions for py3.8 * chore: update changelog Co-authored-by: heitorlessa --- CHANGELOG.md | 1 + aws_lambda_powertools/utilities/parser/models/dynamodb.py | 3 ++- aws_lambda_powertools/utilities/parser/models/kinesis.py | 3 ++- aws_lambda_powertools/utilities/parser/models/s3.py | 3 ++- aws_lambda_powertools/utilities/parser/models/ses.py | 3 ++- aws_lambda_powertools/utilities/parser/models/sns.py | 3 ++- aws_lambda_powertools/utilities/parser/models/sqs.py | 3 ++- aws_lambda_powertools/utilities/parser/types.py | 7 +++++++ pyproject.toml | 2 +- tests/functional/parser/schemas.py | 2 +- 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29fb3a2b4cb..54705c7cae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * **Utilities**: Correctly handle and list multiple exceptions in SQS batch processing utility. * **Docs*:: Fix typos on AppConfig docstring import, and `SnsModel` typo in parser. +* **Utilities**: `typing_extensions` package is now only installed in Python < 3.8 ## [1.10.1] - 2021-01-19 diff --git a/aws_lambda_powertools/utilities/parser/models/dynamodb.py b/aws_lambda_powertools/utilities/parser/models/dynamodb.py index 7bcf68845cc..e7e3094bc9b 100644 --- a/aws_lambda_powertools/utilities/parser/models/dynamodb.py +++ b/aws_lambda_powertools/utilities/parser/models/dynamodb.py @@ -2,7 +2,8 @@ from typing import Any, Dict, List, Optional from pydantic import BaseModel -from typing_extensions import Literal + +from ..types import Literal class DynamoDBStreamChangedRecordModel(BaseModel): diff --git a/aws_lambda_powertools/utilities/parser/models/kinesis.py b/aws_lambda_powertools/utilities/parser/models/kinesis.py index d2852e9f4a8..fa84674727a 100644 --- a/aws_lambda_powertools/utilities/parser/models/kinesis.py +++ b/aws_lambda_powertools/utilities/parser/models/kinesis.py @@ -5,7 +5,8 @@ from pydantic import BaseModel, validator from pydantic.types import PositiveInt -from typing_extensions import Literal + +from ..types import Literal logger = logging.getLogger(__name__) diff --git a/aws_lambda_powertools/utilities/parser/models/s3.py b/aws_lambda_powertools/utilities/parser/models/s3.py index 14ea250b35b..f3559d39908 100644 --- a/aws_lambda_powertools/utilities/parser/models/s3.py +++ b/aws_lambda_powertools/utilities/parser/models/s3.py @@ -5,7 +5,8 @@ from pydantic.fields import Field from pydantic.networks import IPvAnyNetwork from pydantic.types import PositiveInt -from typing_extensions import Literal + +from ..types import Literal class S3EventRecordGlacierRestoreEventData(BaseModel): diff --git a/aws_lambda_powertools/utilities/parser/models/ses.py b/aws_lambda_powertools/utilities/parser/models/ses.py index c82ae03a6c6..70fd2e83978 100644 --- a/aws_lambda_powertools/utilities/parser/models/ses.py +++ b/aws_lambda_powertools/utilities/parser/models/ses.py @@ -4,7 +4,8 @@ from pydantic import BaseModel, Field from pydantic.networks import EmailStr from pydantic.types import PositiveInt -from typing_extensions import Literal + +from ..types import Literal class SesReceiptVerdict(BaseModel): diff --git a/aws_lambda_powertools/utilities/parser/models/sns.py b/aws_lambda_powertools/utilities/parser/models/sns.py index 4da8b1b0977..76bd82531f4 100644 --- a/aws_lambda_powertools/utilities/parser/models/sns.py +++ b/aws_lambda_powertools/utilities/parser/models/sns.py @@ -3,7 +3,8 @@ from pydantic import BaseModel, root_validator from pydantic.networks import HttpUrl -from typing_extensions import Literal + +from ..types import Literal class SnsMsgAttributeModel(BaseModel): diff --git a/aws_lambda_powertools/utilities/parser/models/sqs.py b/aws_lambda_powertools/utilities/parser/models/sqs.py index fd708020492..184b1734f02 100644 --- a/aws_lambda_powertools/utilities/parser/models/sqs.py +++ b/aws_lambda_powertools/utilities/parser/models/sqs.py @@ -2,7 +2,8 @@ from typing import Dict, List, Optional from pydantic import BaseModel -from typing_extensions import Literal + +from ..types import Literal class SqsAttributesModel(BaseModel): diff --git a/aws_lambda_powertools/utilities/parser/types.py b/aws_lambda_powertools/utilities/parser/types.py index cada13b18e3..b19f9c9a87f 100644 --- a/aws_lambda_powertools/utilities/parser/types.py +++ b/aws_lambda_powertools/utilities/parser/types.py @@ -1,6 +1,13 @@ """Generics and other shared types used across parser""" + from typing import TypeVar from pydantic import BaseModel +# We only need typing_extensions for python versions <3.8 +try: + from typing import Literal # noqa: F401 +except ImportError: + from typing_extensions import Literal # noqa: F401 + Model = TypeVar("Model", bound=BaseModel) diff --git a/pyproject.toml b/pyproject.toml index 951b905afd7..719f56054f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ boto3 = "^1.12" jmespath = "^0.10.0" pydantic = {version = "^1.6.0", optional = true } email-validator = {version = "*", optional = true } -typing_extensions = {version = "^3.7.4.2", optional = true } +typing_extensions = {version = "^3.7.4.2", optional = true, python= "<3.8" } [tool.poetry.dev-dependencies] coverage = {extras = ["toml"], version = "^5.0.3"} diff --git a/tests/functional/parser/schemas.py b/tests/functional/parser/schemas.py index f3aa39200a9..a944b4f09c0 100644 --- a/tests/functional/parser/schemas.py +++ b/tests/functional/parser/schemas.py @@ -1,7 +1,6 @@ from typing import Dict, List, Optional from pydantic import BaseModel -from typing_extensions import Literal from aws_lambda_powertools.utilities.parser.models import ( DynamoDBStreamChangedRecordModel, @@ -14,6 +13,7 @@ SqsModel, SqsRecordModel, ) +from aws_lambda_powertools.utilities.parser.types import Literal class MyDynamoBusiness(BaseModel):