py.lib

Yohn Y. 2022-08-25 Parent:4f4cc2fc9805

39:b8d559c989d6 Go to Latest

py.lib/type_utils/type_descriptor.py

+ Возможность воссоздавать объекты классов из кортежей и словарей

History
     1.1 --- a/type_utils/type_descriptor.py	Sat Aug 20 23:56:16 2022 +0300
     1.2 +++ b/type_utils/type_descriptor.py	Thu Aug 25 00:41:37 2022 +0300
     1.3 @@ -70,9 +70,10 @@
     1.4      """\
     1.5      Реализация адаптера над простыми типами
     1.6      """
     1.7 +
     1.8      def __init__(self, type_class, is_nullable=False):
     1.9          super().__init__(type_class.__name__, type_class, is_nullable)
    1.10 -        if type_class in (int, float, bool):
    1.11 +        if type_class in (int, float, bool, complex):
    1.12              self.union_sort_order = 0
    1.13  
    1.14          elif type_class == str:
    1.15 @@ -88,6 +89,13 @@
    1.16          if self.check(val):
    1.17              return val
    1.18  
    1.19 +        if self.union_sort_order == 1:
    1.20 +            if isinstance(val, (list, tuple)):
    1.21 +                return self.t_class(*val)
    1.22 +
    1.23 +            elif isinstance(val, dict):
    1.24 +                return self.t_class(**val)
    1.25 +
    1.26          return self.t_class(val)
    1.27  
    1.28