Skip to content

Commit 70f2028

Browse files
committed
fix parse_func.py
1 parent 692cc27 commit 70f2028

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/dataclass_rest/parse_func.py

+24-21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
TypeAlias,
1111
TypedDict,
1212
Union,
13+
get_type_hints,
1314
)
1415

1516
from .http_request import File
@@ -25,9 +26,9 @@ def get_url_params_from_string(url_template: str) -> List[str]:
2526

2627

2728
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],
3132
) -> Type:
3233
fields = {}
3334
self_processed = False
@@ -37,48 +38,50 @@ def create_query_params_type(
3738
continue
3839
if x in skipped:
3940
continue
40-
fields[x] = spec.annotations.get(x, Any)
41+
fields[x] = get_type_hints(func).get(x, Any)
4142
return TypedDict(f"{func.__name__}_Params", fields)
4243

4344

4445
def create_body_type(
45-
spec: FullArgSpec,
46-
body_param_name: str,
46+
spec: FullArgSpec,
47+
func: Callable,
48+
body_param_name: str,
4749
) -> Type:
48-
return spec.annotations.get(body_param_name, Any)
50+
return get_type_hints(func).get(body_param_name, Any)
4951

5052

5153
def create_response_type(
52-
spec: FullArgSpec,
54+
func: Callable,
5355
) -> Type:
54-
return spec.annotations.get("return", Any)
56+
return get_type_hints(func).get("return", Any)
5557

5658

57-
def get_file_params(spec):
59+
def get_file_params(func: Callable) -> List[str]:
60+
type_hints = get_type_hints(func)
5861
return [
5962
field
60-
for field, field_type in spec.annotations.items()
63+
for field, field_type in type_hints.items()
6164
if isclass(field_type) and issubclass(field_type, File)
6265
]
6366

6467

6568
def get_url_params_from_callable(
66-
url_template: Callable[..., str],
69+
url_template: Callable[..., str],
6770
) -> List[str]:
6871
url_template_func_arg_spec = getfullargspec(url_template)
6972
return url_template_func_arg_spec.args
7073

7174

7275
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,
7982
) -> MethodSpec:
8083
spec = getfullargspec(func)
81-
file_params = get_file_params(spec)
84+
file_params = get_file_params(func)
8285

8386
is_string_url_template = isinstance(url_template, str)
8487
url_template_callable = (
@@ -99,8 +102,8 @@ def parse_func(
99102
url_template=url_template_callable,
100103
url_params=url_params,
101104
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),
104107
body_param_name=body_param_name,
105108
additional_params=additional_params,
106109
is_json_request=is_json_request,

0 commit comments

Comments
 (0)