Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Commit e15960f

Browse files
authored
Merge pull request #24 from sh1ma/develop
pydantic
2 parents b364108 + 492977c commit e15960f

5 files changed

Lines changed: 18 additions & 29 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "apywrapper"
3-
version = "0.0.0"
3+
version = "0.0.0.post123.dev0+96fa6fa"
44
description = "make wrapper for RESTful API"
55
license = "GPL-3.0-or-later"
66
authors = ["sh1ma <in9lude@gmail.com>"]

src/apywrapper/_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ def wrapper(
4545
params = func(*args, **kwargs)
4646
path = Path(path_str, params)
4747
response = request_func(path, params)
48-
if (
48+
if hook_func:
49+
return hook_func(entity, response)
50+
elif (
4951
entity is None or response.status_code == 204
5052
): # entity is None or response body is None
5153
return None
52-
if hook_func:
53-
return hook_func(entity, response)
5454
elif serialize_func:
5555
response.raise_for_status()
5656
return serialize_func(entity, response.json())

src/apywrapper/_types.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
from httpx import Response
99

1010

11-
class DataclassEntityType(Protocol):
12-
# pylint: disable=too-few-public-methods
13-
"""
14-
Entity Object Type on dataclass
15-
"""
16-
17-
__dataclass_fields__: Dict
18-
19-
2011
class PydanticEntityType(Protocol):
2112
"""
2213
Entity Object Type on Pydantic
@@ -25,7 +16,7 @@ class PydanticEntityType(Protocol):
2516
__fields__: Dict
2617

2718

28-
EntityType = Union[DataclassEntityType, PydanticEntityType]
19+
EntityType = PydanticEntityType
2920

3021

3122
Entity = Optional[Union[List[EntityType], EntityType]]

src/apywrapper/_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
"""
44

55
from inspect import signature
6-
from typing import Any, Optional, Type, cast, get_args, get_origin
6+
from typing import Any
77

8-
from ._types import ApiFunc, EntityType
8+
from ._types import ApiFunc
99

1010

11-
def get_returntype_from_annotation(func: ApiFunc) -> Optional[Type[EntityType]]:
11+
def get_returntype_from_annotation(func: ApiFunc) -> Any:
1212
return_annotation = signature(func).return_annotation
13-
if return_annotation is None:
14-
return None
15-
return resolve_returntype(return_annotation)
13+
return return_annotation
1614

1715

18-
def resolve_returntype(tp: Any) -> Type[EntityType]:
19-
if (tp_origin := get_origin(tp)) is not None:
20-
if tp_origin is not list:
21-
return cast(Type[EntityType], get_origin(tp))
22-
return resolve_returntype(get_args(tp)[0])
23-
return cast(Type[EntityType], tp)
16+
# def resolve_returntype(tp: Any) -> Type[EntityType]:
17+
# if (tp_origin := get_origin(tp)) is not None:
18+
# if tp_origin is not list:
19+
# return cast(Type[EntityType], get_origin(tp))
20+
# return resolve_returntype(get_args(tp)[0])
21+
# return cast(Type[EntityType], tp)

tests/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def test4() -> List[Union[str, int]]:
2121
def test5() -> str:
2222
pass
2323

24-
assert get_returntype_from_annotation(test1) is str
25-
assert get_returntype_from_annotation(test2) is dict
24+
assert get_returntype_from_annotation(test1) is List[str]
25+
assert get_returntype_from_annotation(test2) is Dict[str, str]
2626
assert get_returntype_from_annotation(test3) is None
27-
assert get_returntype_from_annotation(test4) is Union
27+
assert get_returntype_from_annotation(test4) is List[Union[str, int]]
2828
assert get_returntype_from_annotation(test5) is str

0 commit comments

Comments
 (0)