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 ncoghlan
Recipients Kevin Shweh, Tijs Van Oevelen, donmez, ezio.melotti, ncoghlan, r.david.murray, rhettinger
Date 2015-12-12.13:38:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
From what I can see:

* checking constant types in addition to their values should be a two line change (plus tests)
* checking the column number in addition to the line number would be a more comprehensive fix, but also a constructor API change (since PyCode_New doesn't currently accept a column parameter)

The "values of the same constant type that are distinct but equivalent may still compare equal" case is obscure enough that I think the lower impact change is likely a better option, especially as 3.x currently "handles" the "lambda: -0.0" case by having both the unfolded 0.0 and the folded -0.0 in the constant list.

Additional detail for those interested:

The lowest impact fix from a code change would be to add a type equivalence check for constants as Raymond first suggested, as that only involves adding an extra check to code_richcompare:

However, the idea of tracking "co_firstcolno" in addition to "co_firstlineno" is a more robust fix, as it means any lexically distinct code objects will necessarily be considered distinct by the interpreter. The downside is that it means touching more code and adding a new public API, since PyCode_New doesn't currently accept a "firstcolno" parameter - code objects are implicitly assumed to be one-per-line.

Out of curiosity, I also went looking for the code in the code generator that collapses the "equivalent" code objects together. The issue is that constants are stored in a dict (mapping them to their co_consts index) during compilation and assembly, so equivalent objects will be merged together (and refer to the index of the first one defined).
Date User Action Args
2015-12-12 13:38:40ncoghlansetrecipients: + ncoghlan, rhettinger, donmez, ezio.melotti, r.david.murray, Kevin Shweh, Tijs Van Oevelen
2015-12-12 13:38:40ncoghlansetmessageid: <>
2015-12-12 13:38:40ncoghlanlinkissue25843 messages
2015-12-12 13:38:39ncoghlancreate