Skip to content

Commit d37bc89

Browse files
author
Pascal Wink
committed
add comments to explain code
1 parent 7d02161 commit d37bc89

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

bunq/sdk/json/converter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ def _str_to_type_from_member_module(cls,
250250
"""
251251
:raise: BunqException when could not find the class for the string.
252252
"""
253+
# First try: direct attribute lookup by name
253254
if cls._DELIMITER_MODULE not in string:
254255
if hasattr(module_, string):
255256
return getattr(module_, string)
256257

258+
# Second try: check for naming conventions based on module type
257259
if "object_" in module_.__name__:
258260
obj_name = string + "Object"
259261
if hasattr(module_, obj_name):
@@ -270,14 +272,18 @@ def _str_to_type_from_member_module(cls,
270272
error_message = cls._ERROR_COULD_NOT_FIND_CLASS.format(string)
271273
raise BunqException(error_message)
272274

275+
# Handle module.class notation using delimiter
273276
module_name_short, class_name = string.split(cls._DELIMITER_MODULE)
274277
members = inspect.getmembers(module_, inspect.ismodule)
275278

279+
# Search through submodules for the class
276280
for name, module_member in members:
277281
if module_name_short == name:
282+
# Try direct class lookup first
278283
if hasattr(module_member, class_name):
279284
return getattr(module_member, class_name)
280285

286+
# Try to find object via naming conventions
281287
if "object_" in module_member.__name__:
282288
obj_name = class_name + "Object"
283289
if hasattr(module_member, obj_name):

bunq/sdk/model/core/bunq_model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,10 @@ def _determine_monetary_account_id(cls, monetary_account_id: int = None) -> int:
141141

142142
@classmethod
143143
def _remove_field_for_request(cls, json_str: str) -> str:
144-
result = json_str.replace(
144+
return json_str.replace(
145145
cls.__STRING_FORMAT_FIELD_FOR_REQUEST_TWO_UNDERSCORE,
146146
cls.__STRING_FORMAT_EMPTY
147147
).replace(
148148
cls.__STRING_FORMAT_FIELD_FOR_REQUEST_ONE_UNDERSCORE,
149149
cls.__STRING_FORMAT_EMPTY
150150
)
151-
152-
return result

0 commit comments

Comments
 (0)