This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eltoder
Recipients Jeremy.Hylton, brett.cannon, eltoder, eric.araujo, ncoghlan, pitrou, rhettinger
Date 2013-01-17.03:41:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1358394105.89.0.0920844035093.issue11983@psf.upfronthosting.co.za>
In-reply-to
Content
My comment will make more sense if you follow the links that I provided.

Brett's check-in (http://hg.python.org/cpython-fullhistory/rev/8127a55a57cb) says that it fixes bug #1190011 (http://www.mail-archive.com/python-bugs-list@python.org/msg02440.html). The bug claims that:

   >> def f(): return ((lambda x=1: x), (lambda x=2: x))
   >> f1, f2 = f()
   >> id(f1.func_code) != id(f2.func_code)

   The above does not hold true.  It should according to
   test_compile (reported in HEAD as bug #1048870).

Certainly comparing co_firstlineno can't fix this, as both lambdas are defined at the same line. There are some more comments by Nick Coghlan on that bug, but I can't find anything clearly stating what the problem is believed to be and what the resolution is.

I understand the reason for Brett's fix and why fixing 1190011 literally is not required. The issue was strange debugger/profiler/etc behavior with identical lambdas defined on _different_ lines. Since python tools typically have line resolution (e.g. debugger doesn't know column position of the current statement), merging lambdas defined on the same line is mostly invisible, and does not cause problems.

So to clarify my opening comment -- this is mostly a documentation issue. The only documentation for the behavior of code cmp is the comment in Include/code.h, which says:

   /* The rest doesn't count for hash or comparisons */

Both hash and compare break this in different ways. At a minimum the comment should be fixed. If the current behavior is considered right, this can be it.

My other point is that we can have code objects with different co_firstlineno compare equal and still not have them deduplicated by the compiler (thus avoid problems with debugger). This can be done similar to how float -0.0 is equal to 0.0, but still not deduplicated. Separating these concerns can allow both most logical compare behavior and good support for debugging.

Re hash legally returning same values for non-equal objects -- sure, only a==b implies hash(a)==hash(b), and not the other way round. But this doesn't mean that we should just return 42 from all hash functions. Not including a field in hash that you include compare needs a very good reason. If there's such a reason in this case, please let me know.
History
Date User Action Args
2013-01-17 03:41:46eltodersetrecipients: + eltoder, brett.cannon, rhettinger, ncoghlan, pitrou, eric.araujo, Jeremy.Hylton
2013-01-17 03:41:45eltodersetmessageid: <1358394105.89.0.0920844035093.issue11983@psf.upfronthosting.co.za>
2013-01-17 03:41:45eltoderlinkissue11983 messages
2013-01-17 03:41:43eltodercreate