Raymond Hettinger added the comment:
Interestingly, co_filename is not used as part of the equivalence criteria, so
code object equivalence can be fooled across multiple input files. Fortunately
in this case, the false equivalence isn't relied on by the code generator.
$ cat a.py
def f():
return 1
$ cat b.py
def f():
return 1.0
$ ./python.exe -q
>>> import a, b
>>> a.f.__code__ == b.f.__code__ # False equivalence
True
>>> a.f()
1
>>> b.f() # Generated code is correct
1.0
Besides aliasing int/float/decimal/fraction/complex/bool, codeobj.__eq__() can
also alias str/unicode on Python 2.7. Likewise, 0.0 and -0.0 can be conflated.
NaNs don't seem to be a problem.
I think we should focus on fixing the spec for code object equivalents.
Perhaps the test can be simplified to use (co_firstlineno, co_firstrowno,
co_filename).
----------
nosy: +arigo, fijall
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25843>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com