Rewrite bfxapi/rest/_Requests.py with type hinting. Add None values erasement in bfxapi/utils/JSONEncoder.py. Update code with new improvements.

This commit is contained in:
Davide Casale
2023-02-06 19:15:58 +01:00
parent 929ae62d2f
commit c588d9f20c
6 changed files with 86 additions and 96 deletions

View File

@@ -1,7 +1,5 @@
from typing import List, Dict, Union, Optional, Any, TypedDict, Generic, TypeVar, cast
from dataclasses import dataclass
from .labeler import _Type, _Serializer
T = TypeVar("T")
@@ -19,10 +17,10 @@ class Notification(_Type, Generic[T]):
class _Notification(_Serializer, Generic[T]):
__LABELS = [ "mts", "type", "message_id", "_PLACEHOLDER", "notify_info", "code", "status", "text" ]
def __init__(self, serializer: Optional[_Serializer] = None, iterate: bool = False):
def __init__(self, serializer: Optional[_Serializer] = None, is_iterable: bool = False):
super().__init__("Notification", Notification, _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
self.serializer, self.iterate = serializer, iterate
self.serializer, self.is_iterable = serializer, is_iterable
def parse(self, *values: Any, skip: Optional[List[str]] = None) -> Notification[T]:
notification = cast(Notification[T], Notification(**dict(self._serialize(*values))))
@@ -30,7 +28,7 @@ class _Notification(_Serializer, Generic[T]):
if isinstance(self.serializer, _Serializer):
NOTIFY_INFO = cast(List[Any], notification.notify_info)
if self.iterate == False:
if self.is_iterable == False:
if len(NOTIFY_INFO) == 1 and isinstance(NOTIFY_INFO[0], list):
NOTIFY_INFO = NOTIFY_INFO[0]