Skip to content

Commit ae2940a

Browse files
Fix Python3.8/3.9
1 parent 90341e4 commit ae2940a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • aws_lambda_powertools/utilities/idempotency/serialization

aws_lambda_powertools/utilities/idempotency/serialization/functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from types import UnionType
21
from typing import Any, Optional, Union, get_args, get_origin
32

3+
try:
4+
from types import UnionType
5+
except ImportError:
6+
UnionType = None
7+
48
from aws_lambda_powertools.utilities.idempotency.exceptions import (
59
IdempotencyModelTypeError,
610
)
@@ -9,24 +13,21 @@
913
def get_actual_type(model_type: Any) -> Any:
1014
"""
1115
Extract the actual type from a potentially Optional or Union type.
12-
1316
This function handles types that may be wrapped in Optional or Union,
1417
including the Python 3.10+ Union syntax (Type | None).
15-
1618
Parameters
1719
----------
1820
model_type: Any
1921
The type to analyze. Can be a simple type, Optional[Type], BaseModel, dataclass
2022
Returns
2123
-------
2224
The actual type without Optional or Union wrappers.
23-
2425
Raises:
2526
IdempotencyModelTypeError: If the type specification is invalid
2627
(e.g., Union with multiple non-None types).
2728
"""
2829
# Check if the type is Optional, Union, or the new Union syntax
29-
if get_origin(model_type) in (Optional, Union, UnionType):
30+
if get_origin(model_type) in (Optional, Union) or (UnionType is not None and get_origin(model_type) is UnionType):
3031
# Get the arguments of the type (e.g., for Optional[int], this would be (int, NoneType))
3132
args = get_args(model_type)
3233

0 commit comments

Comments
 (0)