New issue 1974: Different behaviour for collections of nans from CPython https://bitbucket.org/pypy/pypy/issue/1974/different-behaviour-for-collections-of
David MacIver: All of the following asserts pass in cpython (I've tried on 2.7, 3.3 and 3.4) but some of them fail on pypy (I've tried on pypy-2.5.0 and pypy3-2.4.0). ``` #!python n1 = float('nan') n2 = float('nan') x = [n1] assert n1 in x assert n2 not in x assert x.index(n1) == 0 try: x.index(n2) assert False except ValueError: pass ``` Basically, it seems like in cpython collection methods have a shortcut that treats x and y as equal if x is y even if not x == y. The behaviour for sets is also different. For set like collections CPython treats reference equal nans as equal but other nans as distinct. ``` #!python n1 = float('nan') n2 = float('nan') n3 = float('nan') x = {n1, n2} assert len(x) == 2 assert n1 in x assert n2 in x assert n3 not in x t = {n1} assert t == t assert t == {n1} assert t != {n2} ``` _______________________________________________ pypy-issue mailing list pypy-issue@python.org https://mail.python.org/mailman/listinfo/pypy-issue