[pypy-commit] pypy py3.5: Make the second arg to operator.length_hint() optional
rlamy
pypy.commits at gmail.com
Thu Oct 27 19:59:21 EDT 2016
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r87969:fe3036b40c7f
Date: 2016-10-28 00:58 +0100
http://bitbucket.org/pypy/pypy/changeset/fe3036b40c7f/
Log: Make the second arg to operator.length_hint() optional
diff --git a/pypy/module/operator/interp_operator.py b/pypy/module/operator/interp_operator.py
--- a/pypy/module/operator/interp_operator.py
+++ b/pypy/module/operator/interp_operator.py
@@ -210,7 +210,7 @@
return space.inplace_add(w_obj1, w_obj2)
@unwrap_spec(default=int)
-def length_hint(space, w_iterable, default):
+def length_hint(space, w_iterable, default=0):
"""Return an estimate of the number of items in obj.
This is useful for presizing containers when building from an iterable.
If the object supports len(), the result will be exact.
diff --git a/pypy/module/operator/test/test_operator.py b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -322,3 +322,7 @@
assert operator._compare_digest(u'asd', u'asd')
assert not operator._compare_digest(u'asd', u'qwe')
raises(TypeError, operator._compare_digest, u'asd', b'qwe')
+
+ def test_length_hint(self):
+ import _operator as operator
+ assert operator.length_hint([1, 2]) == 2
More information about the pypy-commit
mailing list