New submission from Harald Husum <harald.hu...@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@python
components: Documentation
messages: 406485
nosy: docs@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue45832>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to