Skip to content

Commit 2d305d0

Browse files
committed
feature/python-sdk-refactor Updated Type Annotations for all the JSON classes.
1 parent 712e963 commit 2d305d0

15 files changed

+192
-492
lines changed

bunq/sdk/http/bunq_response.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3-
# from types import ModuleType
4-
from typing import Dict, TypeVar
3+
from typing import Dict
54

65
from bunq import Pagination
6+
from bunq.sdk.util.type_alias import T
77

88

99
class BunqResponse:
@@ -13,8 +13,6 @@ class BunqResponse:
1313
:type _pagination: Pagination|None
1414
"""
1515

16-
T = TypeVar('T')
17-
1816
def __init__(self,
1917
value: T,
2018
headers: Dict[str, str],

bunq/sdk/json/anchor_object_adapter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from __future__ import annotations
2+
13
from bunq import AnchorObjectInterface
24
from bunq.sdk.exception.bunq_exception import BunqException
35
from bunq.sdk.json import converter
6+
from bunq.sdk.model.core.bunq_model import BunqModel
47
from bunq.sdk.model.generated import endpoint
58
from bunq.sdk.model.generated import object_
9+
from bunq.sdk.util.type_alias import JsonValue
10+
from bunq.sdk.util.type_alias import T
611

712

813
class AnchorObjectAdapter(converter.JsonAdapter):
@@ -16,12 +21,13 @@ class AnchorObjectAdapter(converter.JsonAdapter):
1621
}
1722

1823
@classmethod
19-
def deserialize(cls, cls_target, obj_raw):
24+
def deserialize(cls,
25+
cls_target: Type[T],
26+
obj_raw: JsonValue) -> T:
2027
"""
21-
:type cls_target: BunqModel
22-
:type obj_raw: int|str|bool|float|list|dict|None
2328
24-
:rtype: T
29+
:param cls_target:
30+
:param obj_raw:
2531
"""
2632

2733
model_ = super()._deserialize_default(cls_target, obj_raw)
@@ -42,14 +48,14 @@ def deserialize(cls, cls_target, obj_raw):
4248
return model_
4349

4450
@classmethod
45-
def can_serialize(cls):
51+
def can_serialize(cls) -> bool:
4652
return False
4753

4854
@classmethod
49-
def _get_object_class(cls, class_name):
55+
def _get_object_class(cls, class_name: str) -> BunqModel:
5056
"""
51-
:type class_name: str
52-
:rtype: BunqModel
57+
58+
:param class_name:
5359
"""
5460

5561
class_name = class_name.lstrip(cls.__STRING_FORMAT_UNDERSCORE)
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1+
from typing import Type
2+
13
from bunq.sdk.context.api_environment_type import ApiEnvironmentType
24
from bunq.sdk.json import converter
35

46

57
class ApiEnvironmentTypeAdapter(converter.JsonAdapter):
68
@classmethod
7-
def deserialize(cls, target_class, name):
8-
"""
9-
:type target_class: ApiEnvironmentType|type
10-
:type name: str
11-
12-
:rtype: context.ApiEnvironmentType
13-
"""
14-
9+
def deserialize(cls,
10+
target_class: Type[ApiEnvironmentType],
11+
name: str) -> ApiEnvironmentType:
1512
return ApiEnvironmentType[name]
1613

1714
@classmethod
18-
def serialize(cls, api_environment_type):
19-
"""
20-
:type api_environment_type: ApiEnvironmentType
21-
22-
:rtype: str
23-
"""
24-
15+
def serialize(cls, api_environment_type: ApiEnvironmentType) -> str:
2516
return api_environment_type.name

0 commit comments

Comments
 (0)