Skip to content

Commit 0a832e9

Browse files
committed
feature/sdk_python#139 Removed Type[Any] and replaced it with Type[T].
1 parent 591e374 commit 0a832e9

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

bunq/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Type, Any
1+
from typing import Type
22

33
from bunq.sdk.context.api_environment_type import ApiEnvironmentType
44
from bunq.sdk.context.installation_context import InstallationContext
@@ -42,11 +42,11 @@ def initialize_converter() -> None:
4242
converter.register_adapter(datetime.datetime, DateTimeAdapter)
4343
converter.register_adapter(Pagination, PaginationAdapter)
4444

45-
def register_anchor_adapter(class_to_register: Type[Any]) -> None:
45+
def register_anchor_adapter(class_to_register: Type[T]) -> None:
4646
if issubclass(class_to_register, AnchorObjectInterface):
4747
converter.register_adapter(class_to_register, AnchorObjectAdapter)
4848

49-
def get_class(class_string_to_get: str) -> Type[Any]:
49+
def get_class(class_string_to_get: str) -> Type[T]:
5050
if hasattr(object_, class_string_to_get):
5151
return getattr(object_, class_string_to_get)
5252

bunq/sdk/json/converter.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import typing
88
import warnings
99
from types import ModuleType
10-
from typing import Type, Optional, Callable, Generator, Any, Dict, Match, List, Union, Generic
10+
from typing import Type, Optional, Callable, Generator, Dict, Match, List, Union, Generic
1111

1212
from bunq.sdk.exception.bunq_exception import BunqException
1313
from bunq.sdk.util.type_alias import T, JsonValue
@@ -74,14 +74,14 @@ def register_custom_adapter(cls,
7474
cls._custom_deserializers[class_name] = adapter
7575

7676
@classmethod
77-
def _get_serializer(cls, cls_for: Type[Any]) -> type:
77+
def _get_serializer(cls, cls_for: Type[T]) -> type:
7878
if cls_for.__name__ in cls._custom_serializers:
7979
return cls._custom_serializers[cls_for.__name__]
8080

8181
return JsonAdapter
8282

8383
@classmethod
84-
def _get_deserializer(cls, cls_for: Type[Any]) -> Type[JsonAdapter]:
84+
def _get_deserializer(cls, cls_for: Type[T]) -> Type[JsonAdapter]:
8585
if cls_for.__name__ in cls._custom_deserializers:
8686
return cls._custom_deserializers[cls_for.__name__]
8787

@@ -121,7 +121,7 @@ def _deserialize_default(cls,
121121
@classmethod
122122
def _is_deserialized(cls,
123123
cls_target: Type[T],
124-
obj: Any) -> bool:
124+
obj: T) -> bool:
125125
if cls_target is None:
126126
return True
127127

@@ -151,7 +151,7 @@ def _deserialize_dict(cls,
151151

152152
@classmethod
153153
def _deserialize_dict_attributes(cls,
154-
cls_context: Type[Any],
154+
cls_context: Type[T],
155155
dict_: Dict) -> Dict:
156156
dict_deserialized = {}
157157

@@ -243,7 +243,7 @@ def _str_to_type(cls,
243243
@classmethod
244244
def _str_to_type_from_member_module(cls,
245245
module_: ModuleType,
246-
string: str) -> Type[Any]:
246+
string: str) -> Type[T]:
247247
"""
248248
249249
:raise: BunqException when could not find the class for the string.
@@ -307,7 +307,7 @@ def can_serialize(cls) -> bool:
307307
return True
308308

309309
@classmethod
310-
def serialize(cls, obj: Any) -> JsonValue:
310+
def serialize(cls, obj: T) -> JsonValue:
311311
cls._initialize()
312312
serializer = cls._get_serializer(type(obj))
313313

@@ -317,7 +317,7 @@ def serialize(cls, obj: Any) -> JsonValue:
317317
return serializer.serialize(obj)
318318

319319
@classmethod
320-
def _serialize_default(cls, obj: Any) -> JsonValue:
320+
def _serialize_default(cls, obj: T) -> JsonValue:
321321
if obj is None or cls._is_primitive(obj):
322322
return obj
323323
elif cls._is_bytes(obj):
@@ -330,19 +330,19 @@ def _serialize_default(cls, obj: Any) -> JsonValue:
330330
return cls._serialize_dict(dict_)
331331

332332
@classmethod
333-
def _is_primitive(cls, obj: Any) -> bool:
333+
def _is_primitive(cls, obj: T) -> bool:
334334
return cls._is_type_primitive(type(obj))
335335

336336
@classmethod
337-
def _is_type_primitive(cls, type_: Type[Any]) -> bool:
337+
def _is_type_primitive(cls, type_: Type[T]) -> bool:
338338
return type_ in {int, str, bool, float}
339339

340340
@classmethod
341-
def _is_bytes(cls, obj: Any) -> bool:
341+
def _is_bytes(cls, obj: T) -> bool:
342342
return cls._is_bytes_type(type(obj))
343343

344344
@classmethod
345-
def _is_bytes_type(cls, type_: Type[Any]) -> bool:
345+
def _is_bytes_type(cls, type_: Type[T]) -> bool:
346346
return type_.__name__ in cls._TYPE_NAMES_BYTES
347347

348348
@classmethod
@@ -356,7 +356,7 @@ def _serialize_list(cls, list_: List) -> List:
356356
return list_serialized
357357

358358
@classmethod
359-
def _get_obj_raw(cls, obj: Any) -> Dict:
359+
def _get_obj_raw(cls, obj: T) -> Dict:
360360
return obj if type(obj) == dict else obj.__dict__
361361

362362
@classmethod
@@ -375,32 +375,22 @@ def _serialize_dict(cls, dict_: Dict) -> Dict:
375375

376376

377377
class ValueTypes:
378-
"""
379-
:type _main: type|None
380-
:type _sub: type|None
381-
"""
382-
383378
def __init__(self,
384-
main: Type[Any] = None,
385-
sub: Type[Any] = None) -> None:
379+
main: Type[T] = None,
380+
sub: Type[T] = None) -> None:
386381
self._main = main
387382
self._sub = sub
388383

389384
@property
390-
def main(self) -> Type[Any]:
385+
def main(self) -> Type[T]:
391386
return self._main
392387

393388
@property
394-
def sub(self) -> Type[Any]:
389+
def sub(self) -> Type[T]:
395390
return self._sub
396391

397392

398393
class ValueSpecs:
399-
"""
400-
:type _name: str|None
401-
:type _types: ValueTypes|None
402-
"""
403-
404394
def __init__(self,
405395
name: str = None,
406396
types: ValueTypes = None) -> None:
@@ -444,11 +434,11 @@ def deserialize(cls: Type[T], obj_raw: JsonValue) -> T:
444434
return JsonAdapter.deserialize(cls, obj_raw)
445435

446436

447-
def class_to_json(obj: Any) -> JsonValue:
437+
def class_to_json(obj: T) -> JsonValue:
448438
obj_raw = serialize(obj)
449439

450440
return json.dumps(obj_raw, indent=_JSON_INDENT, sort_keys=True)
451441

452442

453-
def serialize(obj_cls: Any) -> JsonValue:
443+
def serialize(obj_cls: T) -> JsonValue:
454444
return JsonAdapter.serialize(obj_cls)

0 commit comments

Comments
 (0)