Created
June 12, 2012 19:49
-
-
Save smarnach/2919731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(object): | |
def __init__(self, i): | |
self.i = i | |
def __radd__(self, other): | |
return self.i | |
a = [A(42)] | |
# Test with built-in sum() | |
print(sum(a)) | |
# prints 42 | |
def sum(s, start=None): | |
it = iter(s) | |
try: | |
n= next(it) | |
except: | |
return 0 | |
if start is None: | |
start = type(n)() | |
return n + __builtins__.sum(it, start) | |
# Test with proposed new version | |
print(sum(a)) | |
# results in | |
# TypeError: __init__() takes exactly 2 arguments (1 given) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment