[issue23986] Inaccuracy about "in" keyword for list and tuple
New submission from wim glenn: The comparisons section of the python 2 docs says: --- https://docs.python.org/2/reference/expressions.html#comparisons For the list and tuple types, x in y is true if and only if there exists an index i such that x == y[i] is true. --- But it's not strictly speaking correct. Simplest counter-example: x = float('nan') y = [x] The python 3 docs instead mention correct equivalent which is any(x is e or x == e for e in y) ---------- assignee: docs@python components: Documentation messages: 241317 nosy: docs@python, wim.glenn priority: normal severity: normal status: open title: Inaccuracy about "in" keyword for list and tuple type: enhancement versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
James Edwards added the comment: What about: For the list and tuple types, ``x in y`` is true if and only if there exists an -index *i* such that ``x == y[i]`` is true. +index *i* such that either ``x == y[i]`` or ``x is y[i]`` is true. Seems to address your issue, and match the semantics of the Python3 any() approach. ---------- keywords: +patch nosy: +jedwards Added file: http://bugs.python.org/file39087/issue23986.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
R. David Murray added the comment: Those two should be in the reverse order, though. Identity is checked before equality. But why not backport the python3 wording? (Note that there is an open issue for slightly improving that wording). ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
Raymond Hettinger added the comment: I'll add James' suggested wording, but with the reversed-order suggested by David Murray. ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
Roundup Robot added the comment: New changeset aba647a34ed4 by Raymond Hettinger in branch '2.7': Issue #23986: Note that the in-operator for lists and tuples check identity before equality. https://hg.python.org/cpython/rev/aba647a34ed4 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
Changes by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- resolution: -> fixed status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23986> _______________________________________
participants (6)
-
Ezio Melotti
-
James Edwards
-
R. David Murray
-
Raymond Hettinger
-
Roundup Robot
-
wim glenn