[pypy-commit] pypy default: special case nan containment
pjenvey
noreply at buildbot.pypy.org
Wed Jun 19 02:18:53 CEST 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r64934:a052f153e311
Date: 2013-06-18 17:11 -0700
http://bitbucket.org/pypy/pypy/changeset/a052f153e311/
Log: special case nan containment
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1222,8 +1222,7 @@
def _safe_find(self, w_list, obj, start, stop):
l = self.unerase(w_list.lstorage)
for i in range(start, min(stop, len(l))):
- val = l[i]
- if val == obj:
+ if l[i] == obj:
return i
raise ValueError
@@ -1543,6 +1542,18 @@
if reverse:
l.reverse()
+ def _safe_find(self, w_list, obj, start, stop):
+ from rpython.rlib.rfloat import isnan
+ if not isnan(obj):
+ return AbstractUnwrappedStrategy._safe_find(self, w_list, obj,
+ start, stop)
+ # unwrapped nan != nan, finding it requires more effort
+ l = self.unerase(w_list.lstorage)
+ for i in range(start, min(stop, len(l))):
+ if isnan(l[i]):
+ return i
+ raise ValueError
+
class StringListStrategy(AbstractUnwrappedStrategy, ListStrategy):
_none_value = None
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1314,6 +1314,10 @@
non_list = NonList()
assert [] != non_list
+ def test_nan_containment(self):
+ nan = float('nan')
+ assert nan in [nan]
+
class AppTestForRangeLists(AppTestW_ListObject):
spaceconfig = {"objspace.std.withrangelist": True}
More information about the pypy-commit
mailing list