Fix bug regarding new typing with dataclasses.

This commit is contained in:
Davide Casale
2023-01-16 18:18:12 +01:00
parent e185da4cc9
commit 2afcc76647
4 changed files with 57 additions and 54 deletions

View File

@@ -20,12 +20,12 @@ 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):
super().__init__("Notification", _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
super().__init__("Notification", Notification, _Notification.__LABELS, IGNORE = [ "_PLACEHOLDER" ])
self.serializer, self.iterate = serializer, iterate
def parse(self, *values: Any, skip: Optional[List[str]] = None) -> Notification[T]:
notification = cast(Notification[T], _Type(**dict(self._serialize(*values))))
notification = cast(Notification[T], Notification(**dict(self._serialize(*values))))
if isinstance(self.serializer, _Serializer):
NOTIFY_INFO = cast(List[Any], notification.NOTIFY_INFO)
@@ -34,7 +34,7 @@ class _Notification(_Serializer, Generic[T]):
if len(NOTIFY_INFO) == 1 and isinstance(NOTIFY_INFO[0], list):
NOTIFY_INFO = NOTIFY_INFO[0]
notification.NOTIFY_INFO = cast(T, _Type(**dict(self.serializer._serialize(*NOTIFY_INFO, skip=skip))))
else: notification.NOTIFY_INFO = cast(T, [ _Type(**dict(self.serializer._serialize(*data, skip=skip))) for data in NOTIFY_INFO ])
notification.NOTIFY_INFO = cast(T, self.serializer.klass(**dict(self.serializer._serialize(*NOTIFY_INFO, skip=skip))))
else: notification.NOTIFY_INFO = cast(T, [ self.serializer.klass(**dict(self.serializer._serialize(*data, skip=skip))) for data in NOTIFY_INFO ])
return notification