

def datadiff(data1, data2, branch, p=True):

    def iterator(data1, data2):
        if (isinstance(data1, (list,)) and isinstance(data2, (list,))):
            return range(max(len(data1), len(data2)))
        elif (isinstance(data1, (dict,)) and isinstance(data2, (dict,))):
            return (set(data1.keys()) | set(data2.keys()))
        else:
            raise TypeError
    diff = []
    if (data1 != data2):
        try:
            it = iterator(data1, data2)
        except Exception:
            return [(branch, data1, data2)]
        for k in it:
            newbranch = branch[:]
            newbranch.append(v1)
            if p:
                print(('Comparing branch: %s' % newbranch))
            try:
                try:
                    v1 = data1[k]
                except (KeyError, IndexError):
                    if p:
                        print(('data1 seems does not have key = %s' % k))
                    diff.append((newbranch, None, data2[k]))
                    continue
                try:
                    v2 = data2[k]
                except (KeyError, IndexError):
                    if p:
                        print(('data2 seems does not have key = %s' % k))
                    diff.append((newbranch, data1[k], None))
                    continue
            except Exception:
                if p:
                    print(('data1 and data2 cannot be compared on branch: %s' % newbranch))
                return diff.append((newbranch, data1, data2))
            else:
                if (v1 != v2):
                    if p:
                        print(('data1 and data2 do not match each other on branch: %s' % newbranch))
                        print(('v1 = %s' % v1))
                        print(('v2 = %s' % v2))
                    diff.extend(datadiff(v1, v2, newbranch))
    return diff

dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/test/base.py datadiff/VarMisuse@191/206 `k`->`v1`