def unify_object(u, v, s): """ Unify two Python objects Unifies their type and ``__dict__`` attributes >>> from logpy.unifymore import unify_object >>> from logpy import var >>> class Foo(object): ... def __init__(self, a, b): ... self.a = a ... self.b = b ... def __str__(self): ... return "Foo(%s, %s)"%(str(self.a), str(self.b)) >>> x = var('x') >>> f = Foo(1, x) >>> g = Foo(1, 2) >>> unify_object(f, g, {}) {~x: 2} """ if type(u) != type(v): return False return unify_dict(u.__dict__, v.__dict__, s)
def test_unify_dict(): assert unify_dict({1: 2}, {1: 2}, {}) == {} assert unify_dict({1: 2}, {1: 3}, {}) == False assert unify_dict({2: 2}, {1: 2}, {}) == False assert unify_dict({1: var(5)}, {1: 2}, {}) == {var(5): 2}