Skip to content

Commit 56b196e

Browse files
committed
feature/python-sdk-refactor General updates, removing unnecessary docstrings, fixing incorrect type annotations, reformatting code for better readability, etc.
1 parent 250335c commit 56b196e

23 files changed

+99
-475
lines changed

bunq/__init__.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
from typing import Type, Any
2+
13
from bunq.sdk.context.api_environment_type import ApiEnvironmentType
24
from bunq.sdk.context.installation_context import InstallationContext
35
from bunq.sdk.http.pagination import Pagination
46
from bunq.sdk.json import converter
57
from bunq.sdk.model.core.anchor_object_interface import AnchorObjectInterface
8+
from bunq.sdk.util.type_alias import T
69

710

8-
def initialize_converter():
9-
"""
10-
:rtype: None
11-
"""
12-
11+
def initialize_converter() -> None:
1312
import datetime
1413
import inspect
1514

@@ -33,36 +32,21 @@ def initialize_converter():
3332
from bunq.sdk.json.anchor_object_adapter import AnchorObjectAdapter
3433

3534
converter.register_adapter(Installation, InstallationAdapter)
36-
converter.register_adapter(
37-
SessionServer,
38-
SessionServerAdapter
39-
)
40-
converter.register_adapter(
41-
InstallationContext,
42-
InstallationContextAdapter
43-
)
44-
converter.register_adapter(
45-
ApiEnvironmentType,
46-
ApiEnvironmentTypeAdapter
47-
)
35+
converter.register_adapter(SessionServer, SessionServerAdapter)
36+
converter.register_adapter(InstallationContext, InstallationContextAdapter)
37+
converter.register_adapter(ApiEnvironmentType, ApiEnvironmentTypeAdapter)
4838
converter.register_adapter(float, FloatAdapter)
4939
converter.register_adapter(object_.Geolocation, GeolocationAdapter)
50-
converter.register_adapter(
51-
object_.MonetaryAccountReference,
52-
MonetaryAccountReferenceAdapter
53-
)
40+
converter.register_adapter(object_.MonetaryAccountReference, MonetaryAccountReferenceAdapter)
5441
converter.register_adapter(object_.ShareDetail, ShareDetailAdapter)
5542
converter.register_adapter(datetime.datetime, DateTimeAdapter)
5643
converter.register_adapter(Pagination, PaginationAdapter)
5744

58-
def register_anchor_adapter(class_to_register):
45+
def register_anchor_adapter(class_to_register: Type[Any]) -> None:
5946
if issubclass(class_to_register, AnchorObjectInterface):
60-
converter.register_adapter(
61-
class_to_register,
62-
AnchorObjectAdapter
63-
)
47+
converter.register_adapter(class_to_register, AnchorObjectAdapter)
6448

65-
def get_class(class_string_to_get):
49+
def get_class(class_string_to_get: str) -> Type[Any]:
6650
if hasattr(object_, class_string_to_get):
6751
return getattr(object_, class_string_to_get)
6852

bunq/sdk/context/api_context.py

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ def __init__(self,
4646
device_description: str,
4747
permitted_ips: List[str] = None,
4848
proxy_url: List[str] = None) -> None:
49-
"""
50-
51-
:param environment_type:
52-
:param api_key:
53-
:param device_description:
54-
:param permitted_ips:
55-
:param proxy_url:
56-
"""
57-
5849
if permitted_ips is None:
5950
permitted_ips = []
6051

@@ -68,12 +59,6 @@ def __init__(self,
6859
def _initialize(self,
6960
device_description: str,
7061
permitted_ips: List[str]) -> None:
71-
"""
72-
73-
:param device_description:
74-
:param permitted_ips:
75-
"""
76-
7762
self._initialize_installation()
7863
self._register_device(device_description, permitted_ips)
7964
self._initialize_session()
@@ -101,12 +86,6 @@ def _initialize_installation(self) -> None:
10186
def _register_device(self,
10287
device_description: str,
10388
permitted_ips: List[str]) -> None:
104-
"""
105-
106-
:param device_description:
107-
:param permitted_ips:
108-
"""
109-
11089
from bunq.sdk.model.core.device_server_internal import DeviceServerInternal
11190

11291
DeviceServerInternal.create(
@@ -127,25 +106,14 @@ def _initialize_session(self) -> None:
127106
self._session_context = SessionContext(token, expiry_time, user_id)
128107

129108
@classmethod
130-
def _get_expiry_timestamp(cls,
131-
session_server: SessionServer) -> datetime.datetime:
132-
"""
133-
134-
:param session_server:
135-
"""
136-
109+
def _get_expiry_timestamp(cls, session_server: SessionServer) -> datetime.datetime:
137110
timeout_seconds = cls._get_session_timeout_seconds(session_server)
138111
time_now = datetime.datetime.now()
139112

140113
return time_now + datetime.timedelta(seconds=timeout_seconds)
141114

142115
@classmethod
143116
def _get_session_timeout_seconds(cls, session_server: SessionServer) -> int:
144-
"""
145-
146-
:param session_server:
147-
"""
148-
149117
if session_server.user_company is not None:
150118
return session_server.user_company.session_timeout
151119
elif session_server.user_person is not None:
@@ -238,11 +206,6 @@ def proxy_url(self) -> str:
238206
return self._proxy_url
239207

240208
def save(self, path: str = None) -> None:
241-
"""
242-
243-
:param path:
244-
"""
245-
246209
if path is None:
247210
path = self._PATH_API_CONTEXT_DEFAULT
248211

@@ -258,34 +221,23 @@ def to_json(self) -> str:
258221
return converter.class_to_json(self)
259222

260223
@classmethod
261-
def restore(cls, path: str = None) -> 'ApiContext':
262-
"""
263-
264-
:param path:
265-
"""
266-
224+
def restore(cls, path: str = None) -> ApiContext:
267225
if path is None:
268226
path = cls._PATH_API_CONTEXT_DEFAULT
269227

270228
with open(path, cls._FILE_MODE_READ) as file_:
271229
return cls.from_json(file_.read())
272230

273231
@classmethod
274-
def from_json(cls, json_str: str) -> 'ApiContext':
232+
def from_json(cls, json_str: str) -> ApiContext:
275233
"""
276234
Creates an ApiContext instance from JSON string.
277235
278-
:type json_str:
279236
"""
280237

281238
return converter.json_to_class(ApiContext, json_str)
282239

283-
def __eq__(self, other: 'ApiContext') -> bool:
284-
"""
285-
286-
:param other:
287-
"""
288-
240+
def __eq__(self, other: ApiContext) -> bool:
289241
return (self.token == other.token and
290242
self.api_key == other.api_key and
291243
self.environment_type == other.environment_type)

bunq/sdk/context/api_environment_type.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class ApiEnvironmentType(aenum.AutoNumberEnum):
1212
SANDBOX = 'https://public-api.sandbox.bunq.com/v1/'
1313

1414
def __init__(self, uri_base: str) -> None:
15-
"""
16-
17-
:type uri_base:
18-
"""
19-
2015
self._uri_base = uri_base
2116

2217
@property

bunq/sdk/context/bunq_context.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ def __init__(self) -> None:
1616

1717
@classmethod
1818
def load_api_context(cls, api_context: ApiContext) -> None:
19-
"""
20-
21-
:param api_context:
22-
"""
23-
2419
cls._api_context = api_context
2520
cls._user_context = UserContext(api_context.session_context.user_id)
2621
cls._user_context.init_main_monetary_account()
@@ -41,9 +36,4 @@ def user_context(cls) -> UserContext:
4136

4237
@classmethod
4338
def update_api_context(cls, api_context: ApiContext) -> None:
44-
"""
45-
46-
:param api_context:
47-
"""
48-
4939
cls._api_context = api_context

bunq/sdk/context/installation_context.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ def __init__(self,
1313
token: str,
1414
private_key_client: RsaKey,
1515
public_key_server: RsaKey) -> None:
16-
"""
17-
18-
:param token:
19-
:param private_key_client:
20-
:param public_key_server:
21-
"""
22-
2316
self._token = token
2417
self._private_key_client = private_key_client
2518
self._public_key_server = public_key_server

bunq/sdk/context/session_context.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ def __init__(self,
1212
token: str,
1313
expiry_time: datetime.datetime,
1414
user_id: int) -> None:
15-
"""
16-
17-
:param token:
18-
:param expiry_time:
19-
:param user_id:
20-
"""
21-
2215
self._token = token
2316
self._expiry_time = expiry_time
2417
self._user_id = user_id

bunq/sdk/context/user_context.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ class UserContext:
1010
_STATUS_ACTIVE = 'ACTIVE'
1111

1212
def __init__(self, user_id: int) -> None:
13-
"""
14-
15-
:param user_id:
16-
"""
17-
1813
self._user_id = user_id
1914
self._user_person = None
2015
self._user_company = None
@@ -28,11 +23,6 @@ def __get_user_object() -> BunqModel:
2823
return endpoint.User.list().value[0].get_referenced_object()
2924

3025
def _set_user(self, user: BunqModel) -> None:
31-
"""
32-
33-
:param user:
34-
"""
35-
3626
if isinstance(user, endpoint.UserPerson):
3727
self._user_person = user
3828

bunq/sdk/exception/EXCEPTIONS.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ class ApiException(Exception):
2828
def __init__(self,
2929
message: str,
3030
response_code: int) -> None:
31-
"""
32-
33-
:param message:
34-
:param response_code:
35-
"""
36-
3731
pass
3832

3933
@property

bunq/sdk/exception/api_exception.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ def __init__(self,
33
message: str,
44
response_code: int,
55
response_id: str) -> None:
6-
"""
7-
8-
:param message:
9-
:param response_code:
10-
:param response_id:
11-
"""
12-
136
self._response_id = response_id
147
self._message = message
158
self._response_code = response_code

bunq/sdk/exception/bunq_exception.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
class BunqException(Exception):
22
def __init__(self, message: str) -> None:
3-
"""
4-
5-
:param message:
6-
"""
7-
83
super(BunqException, self).__init__(message)

0 commit comments

Comments
 (0)