From 4deeecd8f22f0da9467650dda41e07ac57a3a67b Mon Sep 17 00:00:00 2001 From: Eric Nielsen <4120606+ericbn@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:15:57 -0500 Subject: [PATCH] refactor(typing): move more types into TYPE_CHECKING --- .../event_handler/openapi/compat.py | 11 ++++------- .../event_handler/openapi/types.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/aws_lambda_powertools/event_handler/openapi/compat.py b/aws_lambda_powertools/event_handler/openapi/compat.py index 03e9383dbcb..8d1b27ed9c6 100644 --- a/aws_lambda_powertools/event_handler/openapi/compat.py +++ b/aws_lambda_powertools/event_handler/openapi/compat.py @@ -10,18 +10,14 @@ from dataclasses import dataclass, is_dataclass from enum import Enum -from typing import Any, Deque, FrozenSet, List, Mapping, Sequence, Set, Tuple, Union +from typing import TYPE_CHECKING, Any, Deque, FrozenSet, List, Mapping, Sequence, Set, Tuple, Union from typing_extensions import Annotated, Literal, get_origin, get_args from pydantic import BaseModel, create_model from pydantic.fields import FieldInfo -from aws_lambda_powertools.event_handler.openapi.types import ( - COMPONENT_REF_PREFIX, - ModelNameMap, - UnionType, -) +from aws_lambda_powertools.event_handler.openapi.types import COMPONENT_REF_PREFIX, UnionType from pydantic import TypeAdapter, ValidationError @@ -34,7 +30,8 @@ from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue from pydantic_core import PydanticUndefined, PydanticUndefinedType -from aws_lambda_powertools.event_handler.openapi.types import IncEx +if TYPE_CHECKING: + from aws_lambda_powertools.event_handler.openapi.types import IncExm, ModelNameMap Undefined = PydanticUndefined Required = PydanticUndefined diff --git a/aws_lambda_powertools/event_handler/openapi/types.py b/aws_lambda_powertools/event_handler/openapi/types.py index fcbc3ecbef1..55af90d9f23 100644 --- a/aws_lambda_powertools/event_handler/openapi/types.py +++ b/aws_lambda_powertools/event_handler/openapi/types.py @@ -1,17 +1,19 @@ from __future__ import annotations import types -from enum import Enum from typing import TYPE_CHECKING, Any, Callable, Dict, Set, Type, TypedDict, Union if TYPE_CHECKING: - from pydantic import BaseModel # noqa: F401 + from enum import Enum + + from pydantic import BaseModel from typing_extensions import NotRequired -CacheKey = Union[Callable[..., Any], None] -IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]] -TypeModelOrEnum = Union[Type["BaseModel"], Type[Enum]] -ModelNameMap = Dict[TypeModelOrEnum, str] + CacheKey = Union[Callable[..., Any], None] + IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]] + TypeModelOrEnum = Union[Type["BaseModel"], Type[Enum]] + ModelNameMap = Dict[TypeModelOrEnum, str] + UnionType = getattr(types, "UnionType", Union)