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: The Mapping ABC's __eq__ method should return NotImplemented if the other type is not a Mapping
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, pitrou, rhettinger, stutzbach
Priority: normal Keywords: patch

Created on 2010-05-15 22:08 by stutzbach, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mapping.patch stutzbach, 2010-05-15 22:08 Change Mapping.__eq__ to return NotImplemented if the other type isn't a Mapping
eq-test.patch stutzbach, 2010-05-19 00:27 Add test cases
mapping2.patch stutzbach, 2010-05-21 18:57 Revised patch, with fix and unit tests
Messages (10)
msg105833 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-05-15 22:08
The Mapping ABC's __eq__ method should return NotImplemented if the other type is not a Mapping, to give the other type a chance at the comparison.  Right now it simply returns false.

The comparison methods on the other ABCs in _abcoll.py already return NotImplemented if they don't recognize the other type.
msg105846 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-05-16 02:36
A test would be good.
msg105849 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-05-16 05:06
Will do, sometime this week.
msg106000 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-05-18 19:34
Backport to 2.6 and 3.1?
msg106001 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-05-18 19:36
Yes, I think this is a good candidate for backport. The ABCs are new and their APIs shouldn't contain any obvious bugs such as this.
msg106017 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-05-19 00:27
Here's a patch that adds test cases.  It exercises all of the following special methods on Set and Mapping to ensure that they return NotImplemented if they don't recognize the other type.

    lt, gt, le, ge, eq, ne, or, and, xor, sub

I made the patch against the py3k branch.

I made the test-case patch separate to make it easier to see the before and after behavior of the actual fix.
msg106107 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-05-19 21:55
Will you post to Rietveld, please?
msg106131 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-05-20 04:46
Done: http://codereview.appspot.com/1193044

This is my first time using Rietveld.  Let me know if I've done anything wrong.
msg106257 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-05-21 18:57
Here is a revised patch based on Benjamin's comments on Rietveld.
msg106264 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-05-21 20:52
Fixed in r81414. Thanks for the patch.
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 52975
2010-05-21 20:52:37benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg106264
2010-05-21 18:57:16stutzbachsetfiles: + mapping2.patch

messages: + msg106257
2010-05-20 04:46:58stutzbachsetmessages: + msg106131
2010-05-19 21:55:22benjamin.petersonsetmessages: + msg106107
2010-05-19 00:27:14stutzbachsetfiles: + eq-test.patch

messages: + msg106017
2010-05-18 19:36:31pitrousetnosy: + pitrou

messages: + msg106001
versions: + Python 2.6, Python 3.1
2010-05-18 19:34:19rhettingersetmessages: + msg106000
2010-05-17 21:20:57pitrousetnosy: + rhettinger
2010-05-16 05:06:58stutzbachsetmessages: + msg105849
2010-05-16 02:36:19benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg105846
2010-05-15 22:08:11stutzbachcreate