Author: Matti Picus <[email protected]>
Branch: py3.6
Changeset: r97371:6983e20a5d48
Date: 2019-09-03 12:13 +0200
http://bitbucket.org/pypy/pypy/changeset/6983e20a5d48/
Log: test, fix for range.__bool__
diff --git a/pypy/module/__builtin__/functional.py
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -582,6 +582,8 @@
w_tup = space.newtuple([self.w_length, self.w_start, self.w_step])
return space.hash(w_tup)
+ def descr_bool(self, space):
+ return space.call_method(self.w_length, '__bool__')
W_Range.typedef = TypeDef("range",
__new__ = interp2app(W_Range.descr_new.im_func),
@@ -594,6 +596,7 @@
__contains__ = interp2app(W_Range.descr_contains),
__eq__ = interp2app(W_Range.descr_eq),
__hash__ = interp2app(W_Range.descr_hash),
+ __bool__ = interp2app(W_Range.descr_bool),
count = interp2app(W_Range.descr_count),
index = interp2app(W_Range.descr_index),
start = interp_attrproperty_w('w_start', cls=W_Range),
diff --git a/pypy/module/__builtin__/test/test_builtin.py
b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -402,6 +402,13 @@
raises(TypeError, range, 1, 2, '1')
raises(TypeError, range, 1, 2, 3+2j)
+ def test_range_bool(self):
+ import sys
+ a = range(-sys.maxsize, sys.maxsize)
+ assert bool(a) is True
+ b = range(10, 0)
+ assert bool(b) is False
+
def test_sorted(self):
l = []
sorted_l = sorted(l)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit