[New-bugs-announce] [issue45832] Misleading membersip expression documentation
Harald Husum
report at bugs.python.org
Wed Nov 17 14:00:34 EST 2021
New submission from Harald Husum <harald.husum at gmail.com>:
https://docs.python.org/3/reference/expressions.html#membership-test-operations
> For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression `x in y` is equivalent to `any(x is e or x == e for e in y)`.
Yet:
```py
import pandas as pd
import numpy as np
pd_0_dt = pd.Timedelta(0)
np_0_dt = np.timedelta64(0)
cm = (pd_0_dt, np_0_dt)
d1 = {np_0_dt: pd_0_dt}
d2 = {pd_0_dt: np_0_dt}
def test_membership_doc_claim(candidate_members, dct):
for m in candidate_members:
if m in dct:
assert any(m is e or m == e for e in dct)
if any(m is e or m == e for e in dct):
assert m in dct
if __name__ == "__main__":
test_membership_doc_claim(cm, d1) # Fails
test_membership_doc_claim(cm, d2) # Fails
```
Not too surprised, given the td.__hash__() implementation differs between these classes, but they are considered equal none the less.
Unsure whether it is the dict implementation or the doc claim that needs to budge here.
----------
assignee: docs at python
components: Documentation
messages: 406485
nosy: docs at python, eric.araujo, ezio.melotti, harahu, mdk, willingc
priority: normal
severity: normal
status: open
title: Misleading membersip expression documentation
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45832>
_______________________________________
More information about the New-bugs-announce
mailing list