[pypy-svn] pypy default: Test and fix for an obscure case.
arigo
commits-noreply at bitbucket.org
Fri Feb 25 15:42:54 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r42281:99f9d995f74c
Date: 2011-02-25 14:36 +0100
http://bitbucket.org/pypy/pypy/changeset/99f9d995f74c/
Log: Test and fix for an obscure case.
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
@@ -166,6 +166,12 @@
assert sum([1,2,3]) ==6
assert sum([],5) ==5
assert sum([1,2,3],4) ==10
+ #
+ class Foo(object):
+ def __radd__(self, other):
+ assert other is None
+ return 42
+ assert sum([Foo()], None) == 42
def test_type_selftest(self):
assert type(type) is type
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
@@ -329,15 +329,13 @@
result_w.append(w_res)
return result_w
-def sum(space, w_sequence, w_start=None):
+def sum(space, w_sequence, w_start=0):
"""sum(sequence[, start]) -> value
Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start' (which defaults to 0). When the sequence is
empty, returns start."""
- if space.is_w(w_start, space.w_None):
- w_start = space.wrap(0)
- elif space.is_true(space.isinstance(w_start, space.w_basestring)):
+ if space.is_true(space.isinstance(w_start, space.w_basestring)):
msg = "sum() can't sum strings"
raise OperationError(space.w_TypeError, space.wrap(msg))
w_iter = space.iter(w_sequence)
More information about the Pypy-commit
mailing list