Message256245
The equality of code objects is determined by the code_richcompare() logic in Objects/codeobject.c.
Two code objects are equal if all of their attributes compare equal. That includes co_name, co_argcount, co_kwonlyargcount, co_nlocals, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, and co_cellvars.
At the heart of David Murray's minimal example, the reason the two distinct code objects compare equal is that their co_consts compare as equal.
If you wanted to fix this, code objects would need to recursively check for both normal equality and type equality.
>>> f1 = lambda: 1
>>> f2 = lambda: 1.0
>>> f1.__code__.co_consts == f2.__code__.co_consts
True
>>> map(type, f1.__code__.co_consts) == map(type, f2.__code__.co_consts)
False |
|
Date |
User |
Action |
Args |
2015-12-11 23:29:54 | rhettinger | set | recipients:
+ rhettinger, r.david.murray, Tijs Van Oevelen |
2015-12-11 23:29:54 | rhettinger | set | messageid: <1449876594.77.0.0564201578607.issue25843@psf.upfronthosting.co.za> |
2015-12-11 23:29:54 | rhettinger | link | issue25843 messages |
2015-12-11 23:29:54 | rhettinger | create | |
|