Message126352
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. |
|
Date |
User |
Action |
Args |
2011-01-15 23:52:49 | ncoghlan | set | recipients:
+ ncoghlan, georg.brandl, rhettinger, terry.reedy, mark.dickinson, Devin Jeanpierre, eli.bendersky, docs@python |
2011-01-15 23:52:49 | ncoghlan | set | messageid: <1295135569.26.0.0616941834765.issue10912@psf.upfronthosting.co.za> |
2011-01-15 23:52:47 | ncoghlan | link | issue10912 messages |
2011-01-15 23:52:47 | ncoghlan | create | |
|