[issue10912] PyObject_RichCompare differs in behaviour from PyObject_RichCompareBool ; difference not noted in documentation
New submission from Devin Jeanpierre
Eli Bendersky
Georg Brandl
Eli Bendersky
Eli Bendersky
Nick Coghlan
Eli Bendersky
"It may be worth explicitly pointing out that use cases where this assumption is unacceptable would be better served by direct invocation RichCompare function."
Do you mean write it down in the docs?
----------
_______________________________________
Python tracker
Nick Coghlan
Changes by Éric Araujo
Changes by Raymond Hettinger
Raymond Hettinger
Nick Coghlan
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
Raymond Hettinger
Eli Bendersky
Raymond Hettinger
Nick Coghlan
Roundup Robot
Changes by Eli Bendersky
participants (7)
-
Devin Jeanpierre
-
Eli Bendersky
-
Georg Brandl
-
Nick Coghlan
-
Raymond Hettinger
-
Roundup Robot
-
Éric Araujo