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.

classification
Title: collections.abc sequences don't check identity before equality
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Test identity first in membership operation of ItemsView, ValuesView and Sequence in collections.abc
View: 26915
Assigned To: Nosy List: Devin Jeanpierre, rhettinger
Priority: low Keywords: patch

Created on 2015-01-04 08:05 by Devin Jeanpierre, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sequence_identity.diff rhettinger, 2015-01-04 10:35 Add identity checks to the sequence API (tests still needed) review
Messages (8)
msg233399 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-01-04 08:05
For sequence __contains__ and other scenarios, identity is checked before equality, which I've heard is so that "for x in y: assert x in y" doesn't ever fail with an AssertionError (even with NaN and so on). This is not the case for collections.abc-based sequences, which is a jarring inconsistency.
msg233407 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-01-04 10:00
See Raymond Hettinger's comments in http://bugs.python.org/issue4296 for details on why the usual sequence behavior is deliberate.
msg233411 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-01-04 10:35
While this hasn't proven to be an issue to date (non-reflexive objects don't arise much in practice), the proposed change would make it easier to use the Sequence ABC to create classes that are interoperable with other sequences and that have the clean invariant, "anything added to the sequence will be "in" the sequence".

That said, I don't know if this is really needed.
msg233414 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-01-04 12:04
Thanks for the patch! I was secretly hoping to write it though. :P

Not sure how the code review tool works. The patch looks good to me, except it needs tests IMO. I can write them if you think this is not worth the effort.
msg233436 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-01-05 00:48
Devin, you're welcome to whip-up a patch for the tests for this one.  I don't know if it will go forward though.  I'm leaving it open for a while to see if anyone has objections.

If you want to work another straight-forward ABC patch, have a look at http://bugs.python.org/issue23086
msg233437 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-01-05 03:44
Since both patches will clobber each other (same test method), complicating the review process, I've written the patch for issue23086 first. It's currently waiting on committee review from my employer. Will upload to other issue, and once it's submitted or rejected, I'll add a test patch to this issue too.
msg233439 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-01-05 05:52
Can you submit a contributor agreement as well?
msg233440 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-01-05 06:20
I think that such a thing is meaningless, as I don't own copyright to the patches, my employer (Google) does. But, it can't hurt, so, done.
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67351
2022-01-20 22:53:07iritkatrielsetstatus: open -> closed
superseder: Test identity first in membership operation of ItemsView, ValuesView and Sequence in collections.abc
resolution: duplicate
stage: resolved
2015-01-05 06:20:56Devin Jeanpierresetmessages: + msg233440
2015-01-05 05:52:52rhettingersetmessages: + msg233439
2015-01-05 03:44:33Devin Jeanpierresetmessages: + msg233437
2015-01-05 00:48:06rhettingersetmessages: + msg233436
2015-01-04 12:04:52Devin Jeanpierresetmessages: + msg233414
2015-01-04 10:35:01rhettingersetfiles: + sequence_identity.diff
priority: normal -> low
type: behavior


keywords: + patch
nosy: + rhettinger
messages: + msg233411
2015-01-04 10:00:42Devin Jeanpierresetmessages: + msg233407
2015-01-04 08:05:06Devin Jeanpierrecreate