2
2
3
3
import logging
4
4
from abc import ABC , abstractmethod
5
- from typing import Any , Dict , Optional , TypeVar , Union
5
+ from typing import TYPE_CHECKING , Any , TypeVar
6
6
7
7
from aws_lambda_powertools .utilities .parser .functions import _retrieve_or_set_model_from_cache
8
- from aws_lambda_powertools .utilities .parser .types import T
8
+
9
+ if TYPE_CHECKING :
10
+ from aws_lambda_powertools .utilities .parser .types import T
9
11
10
12
logger = logging .getLogger (__name__ )
11
13
@@ -14,12 +16,12 @@ class BaseEnvelope(ABC):
14
16
"""ABC implementation for creating a supported Envelope"""
15
17
16
18
@staticmethod
17
- def _parse (data : Optional [ Union [ Dict [ str , Any ], Any ]] , model : type [T ]) -> Union [ T , None ] :
19
+ def _parse (data : dict [ str , Any ] | Any | None , model : type [T ]) -> T | None :
18
20
"""Parses envelope data against model provided
19
21
20
22
Parameters
21
23
----------
22
- data : Dict
24
+ data : dict
23
25
Data to be parsed and validated
24
26
model : type[T]
25
27
Data model to parse and validate data against
@@ -43,7 +45,7 @@ def _parse(data: Optional[Union[Dict[str, Any], Any]], model: type[T]) -> Union[
43
45
return adapter .validate_python (data )
44
46
45
47
@abstractmethod
46
- def parse (self , data : Optional [ Union [ Dict [ str , Any ], Any ]] , model : type [T ]):
48
+ def parse (self , data : dict [ str , Any ] | Any | None , model : type [T ]):
47
49
"""Implementation to parse data against envelope model, then against the data model
48
50
49
51
NOTE: Call `_parse` method to fully parse data with model provided.
0 commit comments