[issue4296] Python assumes identity implies equivalence; contradicts NaN

2011-06-27 Thread Sven Marnach
Sven Marnach s...@marnach.net added the comment: The behaviour discussed in this thread does not seem to be reflected in Python's documentation. The documentation of __eq__() [1] doesn't mention that objects should compare equal to themselves. [1]:

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2011-04-28 Thread Terry J. Reedy
Changes by Terry J. Reedy tjre...@udel.edu: -- resolution: - fixed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4296 ___ ___ Python-bugs-list

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-12 Thread Mark Dickinson
Changes by Mark Dickinson [EMAIL PROTECTED]: Removed file: http://bugs.python.org/file11989/issue4296.patch ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4296 ___

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-12 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: Before committing, please add one other test that verifies the relationship between in in membership tests and in in a for-loop: Added. (To test_contains, since this seems like a more appropriate place than test_float.) Added file:

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-12 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: Mark, would you do the honor, please? ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4296 ___ ___

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-12 Thread Raymond Hettinger
Raymond Hettinger [EMAIL PROTECTED] added the comment: Reviewed the updated patch and all is well. Thanks. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4296 ___

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-12 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: Committed, r67204. Thanks guys, and thanks especially to Michael for spotting this before 3.0 final. -- status: open - closed ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4296

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: This is indeed interesting. For what it's worth, I think the Python 3.0 behaviour is the right one, here. Perhaps it's worth adding a test to Python 3.0 to make sure that this behaviour doesn't accidentally disappear, or at least to make sure

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: [Raymond] assuming basic invariants. In 2.6, all of the following are always true: assert a in [a] assert a in (a,) assert a in set([a]) assert [a].count(a) == 1 And these are all still true in 3.0 as well, aren't they? In any

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Raymond Hettinger
Raymond Hettinger [EMAIL PROTECTED] added the comment: To be clear, I'm saying that PyObject_RichCompareBool() needs to add-back the code: /* Quick result when objects are the same. Guarantees that identity implies equality. */ if (v == w) { if (op ==

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Michael B Curtis
Michael B Curtis [EMAIL PROTECTED] added the comment: All, Thank you for your rigorous analysis of this bug. To answer the question of the impact of this bug: the real issue that caused problems for our application was Python deciding to silently cast NaN falues to 0L, as discussed here:

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: The issue with nan - 0L was fixed in Python 2.6. I can't recall if I fixed it or somebody else but I know it was discussed. $ python2.6 long(float(nan)) Traceback (most recent call last): File stdin, line 1, in module ValueError: cannot

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Raymond Hettinger
Raymond Hettinger [EMAIL PROTECTED] added the comment: Mark, thanks for checking that all the tests still pass. Please do add back the missing lines in PyObject_RichCompareBool(). It seems that their removal was not a necessary part of eliminating default sort-ordering.

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: Taking it out probably had something to do with NaNs, but this discussion needs to avoid getting lost in NaN paradoxes and instead focus on a notion of membership that is ALWAYS true given object identity. This is an essential pragmatism

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: Here is a tes case for 3.0 -- keywords: +patch Added file: http://bugs.python.org/file11984/issue4296_test.patch ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4296

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: One more data point: in both 2.x and 3.x, sets behave like the 2.x lists: Python 3.0rc2+ (py3k:67177M, Nov 10 2008, 16:06:34) [GCC 4.0.1 (Apple Inc. build 5488)] on darwin Type help, copyright, credits or license for more information. s =

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Raymond Hettinger
Raymond Hettinger [EMAIL PROTECTED] added the comment: I'm not happy with the 3.0 change. IMO, the best behavior is the one that allows code reviewers to correctly reason about the code by assuming basic invariants. In 2.6, all of the following are always true: assert a in [a] assert a

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: Here's a patch incorporating Christian's tests, the missing lines from PyObject_RichCompareBool, and some additional tests to check that [x] == [x] and the like remain True even when x is a NaN. Oh, and a Misc/NEWS entry. With this patch,

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: Oh h... Raymond, you are so right! I was too tired to think of all implications related to the different semantic in 3.0, especially the for in / is in invariant. I'm including Guido and Barry into the discussion. This topic needs some

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: The tests are passing on Ubuntu Linux 64bit, too. Good work everybody! -- assignee: gvanrossum - barry stage: test needed - patch review ___ Python tracker [EMAIL PROTECTED]

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Mark Dickinson
Mark Dickinson [EMAIL PROTECTED] added the comment: With the lines Raymond mentions restored, all tests (including the extra tests Christian's posted here) pass for me, and I also get: a = [float('nan')] a == a True Incidentally, it looks as though the PyObject_RichCompareBool lines were

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-11 Thread Raymond Hettinger
Raymond Hettinger [EMAIL PROTECTED] added the comment: Mark, the patch looks good. Thanks. Before committing, please add one other test that verifies the relationship between in in membership tests and in in a for-loop: for constructor in list, tuple, dict.fromkeys, set, collections.deque:

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-10 Thread Michael B Curtis
New submission from Michael B Curtis [EMAIL PROTECTED]: Found in Python 2.4; not sure what other versions may be affected. I noticed a contradiction with regards to equivalence when experimenting with NaN, which has the special property that it is itself, but it doesn't == itself: a =

[issue4296] Python assumes identity implies equivalence; contradicts NaN

2008-11-10 Thread Christian Heimes
Christian Heimes [EMAIL PROTECTED] added the comment: Interesting, Python 3.0 behaves differently than Python 2.x. Nice catch! :) Python 3.0rc2 (r30rc2:67177, Nov 10 2008, 12:12:09) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type help, copyright, credits or license for more information. nan