[pypy-commit] pypy default: (antocuni, amaury and arigato around): bah, space.bool_w does not work generally. Use space.nonzero instead
antocuni
noreply at buildbot.pypy.org
Tue Apr 17 11:25:03 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r54455:cf29881e5624
Date: 2012-04-17 11:24 +0200
http://bitbucket.org/pypy/pypy/changeset/cf29881e5624/
Log: (antocuni, amaury and arigato around): bah, space.bool_w does not
work generally. Use space.nonzero instead
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -415,7 +415,7 @@
w_descr = space.lookup(w_container, '__contains__')
if w_descr is not None:
w_result = space.get_and_call_function(w_descr, w_container, w_item)
- return space.wrap(space.bool_w(w_result))
+ return space.nonzero(w_result)
return space._contains(w_container, w_item)
def _contains(space, w_container, w_item):
diff --git a/pypy/objspace/test/test_descroperation.py b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -697,10 +697,15 @@
def test_bool___contains__(self):
class X(object):
def __contains__(self, item):
- return 42
+ if item == 'foo':
+ return 42
+ else:
+ return 'hello world'
x = X()
res = 'foo' in x
assert res is True
+ res = 'bar' in x
+ assert res is True
#
class CannotConvertToBool(object):
def __nonzero__(self):
More information about the pypy-commit
mailing list