10
10
TypeAlias ,
11
11
TypedDict ,
12
12
Union ,
13
+ get_type_hints ,
13
14
)
14
15
15
16
from .http_request import File
@@ -25,9 +26,9 @@ def get_url_params_from_string(url_template: str) -> List[str]:
25
26
26
27
27
28
def create_query_params_type (
28
- spec : FullArgSpec ,
29
- func : Callable ,
30
- skipped : Sequence [str ],
29
+ spec : FullArgSpec ,
30
+ func : Callable ,
31
+ skipped : Sequence [str ],
31
32
) -> Type :
32
33
fields = {}
33
34
self_processed = False
@@ -37,48 +38,50 @@ def create_query_params_type(
37
38
continue
38
39
if x in skipped :
39
40
continue
40
- fields [x ] = spec . annotations .get (x , Any )
41
+ fields [x ] = get_type_hints ( func ) .get (x , Any )
41
42
return TypedDict (f"{ func .__name__ } _Params" , fields )
42
43
43
44
44
45
def create_body_type (
45
- spec : FullArgSpec ,
46
- body_param_name : str ,
46
+ spec : FullArgSpec ,
47
+ func : Callable ,
48
+ body_param_name : str ,
47
49
) -> Type :
48
- return spec . annotations .get (body_param_name , Any )
50
+ return get_type_hints ( func ) .get (body_param_name , Any )
49
51
50
52
51
53
def create_response_type (
52
- spec : FullArgSpec ,
54
+ func : Callable ,
53
55
) -> Type :
54
- return spec . annotations .get ("return" , Any )
56
+ return get_type_hints ( func ) .get ("return" , Any )
55
57
56
58
57
- def get_file_params (spec ):
59
+ def get_file_params (func : Callable ) -> List [str ]:
60
+ type_hints = get_type_hints (func )
58
61
return [
59
62
field
60
- for field , field_type in spec . annotations .items ()
63
+ for field , field_type in type_hints .items ()
61
64
if isclass (field_type ) and issubclass (field_type , File )
62
65
]
63
66
64
67
65
68
def get_url_params_from_callable (
66
- url_template : Callable [..., str ],
69
+ url_template : Callable [..., str ],
67
70
) -> List [str ]:
68
71
url_template_func_arg_spec = getfullargspec (url_template )
69
72
return url_template_func_arg_spec .args
70
73
71
74
72
75
def parse_func (
73
- func : Callable ,
74
- method : str ,
75
- url_template : UrlTemplate ,
76
- additional_params : Dict [str , Any ],
77
- is_json_request : bool , # noqa: FBT001
78
- body_param_name : str ,
76
+ func : Callable ,
77
+ method : str ,
78
+ url_template : UrlTemplate ,
79
+ additional_params : Dict [str , Any ],
80
+ is_json_request : bool , # noqa: FBT001
81
+ body_param_name : str ,
79
82
) -> MethodSpec :
80
83
spec = getfullargspec (func )
81
- file_params = get_file_params (spec )
84
+ file_params = get_file_params (func )
82
85
83
86
is_string_url_template = isinstance (url_template , str )
84
87
url_template_callable = (
@@ -99,8 +102,8 @@ def parse_func(
99
102
url_template = url_template_callable ,
100
103
url_params = url_params ,
101
104
query_params_type = create_query_params_type (spec , func , skipped_params ),
102
- body_type = create_body_type (spec , body_param_name ),
103
- response_type = create_response_type (spec ),
105
+ body_type = create_body_type (spec , func , body_param_name ),
106
+ response_type = create_response_type (func ),
104
107
body_param_name = body_param_name ,
105
108
additional_params = additional_params ,
106
109
is_json_request = is_json_request ,
0 commit comments