def f(x):
def g():
return x
return g
g1, g2 = f(1), f(2)
# Equal code, inequivalent functions
print g1.func_code == g2.func_code
print g1.func_code.co_code == g2.func_code.co_code
print g1() == g2()
print
def f(x):
y = x**2 + 1
return y
def g(x):
a = x**2
b = a + 1
return b
# Unequal code, equivalent functions
print f.func_code == g.func_code
print f.func_code.co_code == g.func_code.co_code
print
def f():
return 1
def g():
return 2
# Just to show that comparing co_code in particular is extremely wrong.
print f.func_code.co_code == g.func_code.co_code
ZGVmIGYoeCk6CglkZWYgZygpOgoJCXJldHVybiB4CglyZXR1cm4gZwoKZzEsIGcyID0gZigxKSwgZigyKQoKIyBFcXVhbCBjb2RlLCBpbmVxdWl2YWxlbnQgZnVuY3Rpb25zCnByaW50IGcxLmZ1bmNfY29kZSA9PSBnMi5mdW5jX2NvZGUKcHJpbnQgZzEuZnVuY19jb2RlLmNvX2NvZGUgPT0gZzIuZnVuY19jb2RlLmNvX2NvZGUKcHJpbnQgZzEoKSA9PSBnMigpCgpwcmludAoKZGVmIGYoeCk6CiAgICB5ID0geCoqMiArIDEKICAgIHJldHVybiB5CgpkZWYgZyh4KToKICAgIGEgPSB4KioyCiAgICBiID0gYSArIDEKICAgIHJldHVybiBiCgojIFVuZXF1YWwgY29kZSwgZXF1aXZhbGVudCBmdW5jdGlvbnMKcHJpbnQgZi5mdW5jX2NvZGUgPT0gZy5mdW5jX2NvZGUKcHJpbnQgZi5mdW5jX2NvZGUuY29fY29kZSA9PSBnLmZ1bmNfY29kZS5jb19jb2RlCgpwcmludAoKZGVmIGYoKToKCXJldHVybiAxCgpkZWYgZygpOgoJcmV0dXJuIDIKCiMgSnVzdCB0byBzaG93IHRoYXQgY29tcGFyaW5nIGNvX2NvZGUgaW4gcGFydGljdWxhciBpcyBleHRyZW1lbHkgd3JvbmcuCgpwcmludCBmLmZ1bmNfY29kZS5jb19jb2RlID09IGcuZnVuY19jb2RlLmNvX2NvZGU=