homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inaccuracy about "in" keyword for list and tuple
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: docs@python, jedwards, python-dev, r.david.murray, rhettinger, wim.glenn
Priority: normal Keywords: patch

Created on 2015年04月17日 07:22 by wim.glenn, last changed 2022年04月11日 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue23986.diff jedwards, 2015年04月17日 17:06 review
Messages (5)
msg241317 - (view) Author: wim glenn (wim.glenn) * Date: 2015年04月17日 07:22
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)
msg241344 - (view) Author: James Edwards (jedwards) * Date: 2015年04月17日 17:06
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.
msg241363 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年04月17日 20:25
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).
msg241598 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015年04月20日 04:05
I'll add James' suggested wording, but with the reversed-order suggested by David Murray.
msg264230 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016年04月26日 07:59
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 
History
Date User Action Args
2022年04月11日 14:58:15adminsetgithub: 68174
2016年04月26日 08:00:31rhettingersetstatus: open -> closed
resolution: fixed
2016年04月26日 07:59:24python-devsetnosy: + python-dev
messages: + msg264230
2016年01月03日 10:06:50ezio.melottisetstage: patch review
2015年04月20日 04:05:23rhettingersetassignee: docs@python -> rhettinger

messages: + msg241598
nosy: + rhettinger
2015年04月17日 20:25:51r.david.murraysetnosy: + r.david.murray
messages: + msg241363
2015年04月17日 17:06:31jedwardssetfiles: + issue23986.diff

nosy: + jedwards
messages: + msg241344

keywords: + patch
2015年04月17日 07:22:58wim.glenncreate

AltStyle によって変換されたページ (->オリジナル) /