Nick Coghlan <ncogh...@gmail.com> added the comment:

Indeed. I was actually wondering if it would be worth trying to write up a 
section for the language reference to describe the cases where a Python 
implementation is *expected* to assume reflexive equality. We (IMO) have a 
problem at the moment due to situations like:

>>> class PyContains(list):
...   def __contains__(self, obj):
...     return any(x==obj for x in self)
... 
>>> nan = float("nan")
>>> nan in [nan]
True
>>> nan in PyContains([nan])
False

This is a bug in the __contains__ definition (it should use "x is obj or x == 
obj" rather than just the latter expression) but there isn't anything in the 
language reference to point that out.

Assuming reflexive equality in some places and not in others based on the 
underlying implementation language is going to be a source of subtle bugs 
relating to types like float and decimal.Decimal.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10912>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to