def test_abstract_clone(): s1 = S(t=ty.Int[32]) s2 = S(t=ty.Int[64]) assert upcast(s1, 64) is s2 a1 = T([s1, AbstractClass(object, {'field': s1}, {})]) a2 = T([s2, AbstractClass(object, {'field': s2}, {})]) assert upcast(a1, 64) is a2
def test_abstract_clone(): s1 = S(t=ty.Int[32]) s2 = S(t=ty.Int[64]) assert upcast(s1, 64) is s2 a1 = T([s1, AbstractClass(object, {"field": s1})]) a2 = T([s2, AbstractClass(object, {"field": s2})]) assert upcast(a1, 64) is a2 jt = TransformedFunction(AbstractFunctionUnique((s1, ), s1), P.J) assert upcast(jt, 64).fn.args == [s2] assert upcast(jt, 64).fn.output is s2
def test_merge_edge_cases(): a = {1, 2, 3} b = {1, 2, 3} assert amerge(a, b) is a a = AbstractJTagged(ANYTHING) b = AbstractJTagged(123) assert amerge(a, b) is a a = AbstractClass(object, {'x': ANYTHING, 'y': ANYTHING}, {}) b = AbstractClass(object, {'x': 123, 'y': ANYTHING}, {}) assert amerge(a, b) is a
def to_abstract_test(self, x: object): if is_dataclass(x): typ = dtype.pytype_to_myiatype(type(x), x) new_args = {} for name, field in x.__dataclass_fields__.items(): new_args[name] = self(getattr(x, name)) return AbstractClass(typ.tag, new_args, typ.methods) else: raise Exception(f'Cannot convert: {x}')
def to_abstract_test(self, x: object): if is_dataclass(x): new_args = {} for name, value in dataclass_fields(x).items(): new_args[name] = self(value) return AbstractClass(type(x), new_args, dataclass_methods(type(x))) elif getattr(x, '__origin__') is dtype.External: arg, = x.__args__ return AbstractExternal({VALUE: ANYTHING, TYPE: arg}) else: raise Exception(f'Cannot convert: {x}')