@@ -87,18 +87,21 @@ def reduce_init(clazz, **d):
8787 if type(sub) == str:
8888 sub = eval(sub) # attrs turns these into strings...why?
8989 while sub.__name__ == "Optional":
90- sub = sub.__args__[0] # Reduce Optional[T] -> T
91- reduce_arg = getattr(sub, "__args__", [None])[0]
90+ sub = sub.__args__[0] # Reduce Optional[T] -> T
91+ reduce_arg = getattr(sub, "__args__", [None])[0]
9292 if k in REFERENCED_ARGS: # Directly refcounted
9393 reduce_arg = sub = lambda x: x
9494 if reduce_arg is not None and isinstance(d[k], list):
95- if hasattr(reduce_arg, "__annotations__"):
95+ if hasattr(reduce_arg, "__annotations__") or hasattr(reduce_arg, "__args__") :
9696 setattr(self, k, [reduce_arg(**x) for x in d[k]])
9797 else:
9898 setattr(self, k, [reduce_arg(x) for x in d[k]])
9999 elif reduce_arg is not None and isinstance(d[k], dict) and hasattr(sub, "__annotations__"):
100100 setattr(self, k, sub(**d[k]))
101101 else:
102+ # Reduce typings to respective types
103+ if hasattr(sub, "__origin__") and sub.__origin__ is not None:
104+ sub = sub.__origin__
102105 if isinstance(d[k], dict):
103106 setattr(self, k, sub(**d[k]))
104107 else:
@@ -127,6 +130,7 @@ def __save(self):
127130 return clazz
128131 return __inner
129132
133+
130134# Helper functions
131135def UTTCGen_GetClass(src: MonoBehaviour | str) -> Type:
132136 """Get the class definition from MonoBehaviour or a full type name."""
@@ -361,9 +365,7 @@ def __encoder(obj):
361365 # Skip parent fields at lvl1
362366 continue
363367 if i + 1 < len (fields ) and fields [i + 1 ].m_Type == "Array" :
364- if field .m_Type .startswith ("List" ):
365- # Rename this to Type[]
366- field .m_Type = fields [i + 3 ].m_Type + "[]"
368+ field .m_Type = fields [i + 3 ].m_Type + "[]"
367369 name , type = field .m_Name , translate_type (
368370 field .m_Type , typenames = classname_nodes | import_defs
369371 )
0 commit comments