-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored CPython37 branch #1
base: CPython37
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ def getx(self): | |
return self.__x | ||
|
||
def setx(self, x): | ||
if x < 0: x = 0 | ||
x = max(x, 0) | ||
self.__x = x | ||
|
||
x = property(getx, setx) | ||
|
@@ -99,7 +99,7 @@ def __init__(self): | |
def getx(self): | ||
return self.__x | ||
def setx(self, x): | ||
if x < 0: x = 0 | ||
x = max(x, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.__x = x | ||
x = property(getx, setx) | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
try: | ||
def firstn(g, n): | ||
return [next(g) for i in range(n)] | ||
return [next(g) for _ in range(n)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
def intsfrom(i): | ||
while 1: | ||
|
@@ -48,8 +48,7 @@ def sieve(ints): | |
prime = next(ints) | ||
yield prime | ||
not_divisible_by_prime = exclude_multiples(prime, ints) | ||
for p in sieve(not_divisible_by_prime): | ||
yield p | ||
yield from sieve(not_divisible_by_prime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -114,10 +113,9 @@ def m235(): | |
me_times2 = times(2, m235()) | ||
me_times3 = times(3, m235()) | ||
me_times5 = times(5, m235()) | ||
for i in merge(merge(me_times2, | ||
yield from merge(merge(me_times2, | ||
me_times3), | ||
me_times5): | ||
yield i | ||
me_times5) | ||
Comment on lines
-117
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
# Don't print "too many" of these -- the implementation above is extremely | ||
# inefficient: each call of m235() leads to 3 recursive calls, and in | ||
|
@@ -167,10 +165,9 @@ def m235(): | |
me_times2 = times(2, m235) | ||
me_times3 = times(3, m235) | ||
me_times5 = times(5, m235) | ||
for i in merge(merge(me_times2, | ||
yield from merge(merge(me_times2, | ||
me_times3), | ||
me_times5): | ||
yield i | ||
me_times5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
# Print as many of these as you like -- *this* implementation is memory- | ||
# efficient. | ||
|
@@ -205,8 +202,7 @@ def sum(g, h): | |
|
||
def tail(g): | ||
next(g) # throw first away | ||
for x in g: | ||
yield x | ||
yield from g | ||
Comment on lines
-208
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
yield a | ||
yield b | ||
|
@@ -243,10 +239,9 @@ def tail(g): | |
def m235(): | ||
def _m235(): | ||
yield 1 | ||
for n in merge(times(2, m2), | ||
yield from merge(times(2, m2), | ||
merge(times(3, m3), | ||
times(5, m5))): | ||
yield n | ||
times(5, m5))) | ||
Comment on lines
-246
to
+244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
m1 = _m235() | ||
m2, m3, m5, mRes = tee(m1, 4) | ||
return mRes | ||
|
@@ -291,8 +286,7 @@ def _fib(): | |
yield 1 | ||
yield 2 | ||
next(fibTail) # throw first away | ||
for res in _isum(fibHead, fibTail): | ||
yield res | ||
yield from _isum(fibHead, fibTail) | ||
Comment on lines
-294
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
realfib = _fib() | ||
fibHead, fibTail, fibRes = tee(realfib, 3) | ||
|
@@ -450,8 +444,7 @@ def gencopy(iterator): | |
|
||
try: | ||
def g(): | ||
i = next(me) | ||
yield i | ||
yield next(me) | ||
Comment on lines
-453
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -618,11 +611,9 @@ def tree(list): | |
try: | ||
def inorder(t): | ||
if t: | ||
for x in inorder(t.left): | ||
yield x | ||
yield from inorder(t.left) | ||
yield t.label | ||
for x in inorder(t.right): | ||
yield x | ||
yield from inorder(t.right) | ||
Comment on lines
-621
to
+616
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -637,7 +628,7 @@ def inorder(t): | |
|
||
try: | ||
def g(): | ||
for i in range(3): | ||
for _ in range(3): | ||
Comment on lines
-640
to
+631
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
yield None | ||
yield None | ||
return | ||
|
@@ -691,8 +682,7 @@ def gcomb(x, k): | |
c.insert(0, first) | ||
yield c | ||
# If it doesn't contain first, it's a k comb of rest. | ||
for c in gcomb(rest, k): | ||
yield c | ||
yield from gcomb(rest, k) | ||
Comment on lines
-694
to
+685
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
# | ||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -860,8 +850,7 @@ def __init__(self, name): | |
def generate(self): | ||
while not self.parent: | ||
yield self | ||
for x in self.parent.generator: | ||
yield x | ||
yield from self.parent.generator | ||
Comment on lines
-863
to
+853
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def find(self): | ||
return next(self.generator) | ||
|
@@ -922,12 +911,11 @@ def f(): | |
# | ||
def f(): | ||
try: | ||
try: | ||
1//0 | ||
except ZeroDivisionError: | ||
yield 666 | ||
except: | ||
pass | ||
1//0 | ||
except ZeroDivisionError: | ||
yield 666 | ||
except: | ||
pass | ||
Comment on lines
-925
to
+918
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
finally: | ||
pass | ||
# | ||
|
@@ -976,8 +964,7 @@ def f(): | |
|
||
try: | ||
def f(): | ||
if 0: | ||
yield | ||
pass | ||
Comment on lines
-979
to
+967
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -993,8 +980,7 @@ def f(): | |
|
||
try: | ||
def f(): | ||
if 0: | ||
yield 1 | ||
pass | ||
Comment on lines
-996
to
+983
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1010,8 +996,7 @@ def f(): | |
|
||
try: | ||
def f(): | ||
if "": | ||
yield None | ||
pass | ||
Comment on lines
-1013
to
+999
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1028,25 +1013,6 @@ def f(): | |
try: | ||
def f(): | ||
return | ||
try: | ||
if x==4: | ||
pass | ||
elif 0: | ||
try: | ||
1//0 | ||
except SyntaxError: | ||
pass | ||
else: | ||
if 0: | ||
while 12: | ||
x += 1 | ||
yield 2 # don't blink | ||
f(a, b, c, d, e) | ||
else: | ||
pass | ||
except: | ||
x = 1 | ||
return | ||
Comment on lines
-1031
to
-1049
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1101,10 +1067,7 @@ def f(self): | |
|
||
try: | ||
def f(): | ||
if 0: | ||
return | ||
if 0: | ||
yield 2 | ||
pass | ||
Comment on lines
-1104
to
+1070
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1315,7 +1278,6 @@ def f(): | |
def f(): | ||
yield 1 | ||
return | ||
yield 2 # never reached | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1412,8 +1374,7 @@ def g3(): | |
|
||
try: | ||
def yrange(n): | ||
for i in range(n): | ||
yield i | ||
yield from range(n) | ||
Comment on lines
-1415
to
+1377
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1451,8 +1412,7 @@ def caller(): | |
|
||
try: | ||
def zrange(n): | ||
for i in yrange(n): | ||
yield i | ||
yield from yrange(n) | ||
Comment on lines
-1454
to
+1415
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -1661,7 +1621,8 @@ def f(): yield | |
|
||
|
||
try: | ||
def f(): list(i for i in [(yield 26)]) | ||
def f(): | ||
list([(yield 26)]) | ||
Comment on lines
-1664
to
+1625
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,15 @@ | |
|
||
try: | ||
print('Line 8') | ||
print(list((i,j) for i in range(3) for j in range(4) ) | ||
) | ||
print([(i,j) for i in range(3) for j in range(4)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
||
try: | ||
print('Line 14') | ||
print(list((i,j) for i in range(4) for j in range(i) ) | ||
) | ||
print([(i,j) for i in range(4) for j in range(i)]) | ||
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -34,8 +32,7 @@ | |
|
||
try: | ||
print('Line 21') | ||
print(sum(i*i for i in range(100)) | ||
) | ||
print(sum(i**2 for i in range(100))) | ||
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -51,7 +48,7 @@ | |
|
||
|
||
try: | ||
g = (i*i for i in range(4)) | ||
g = (i**2 for i in range(4)) | ||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -75,7 +72,7 @@ | |
|
||
|
||
try: | ||
g = (i*i for i in range(3)) | ||
g = (i**2 for i in range(3)) | ||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -338,8 +335,7 @@ def caller(): | |
|
||
try: | ||
def zrange(n): | ||
for i in yrange(n): | ||
yield i | ||
yield from yrange(n) | ||
Comment on lines
-341
to
+338
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,13 +216,12 @@ def unique_everseen(iterable, key=None): | |
# unique_everseen('ABBCcAD', str.lower) --> A B C D | ||
seen = set() | ||
seen_add = seen.add | ||
if key is None: | ||
for element in iterable: | ||
for element in iterable: | ||
if key is None: | ||
if element not in seen: | ||
seen_add(element) | ||
yield element | ||
else: | ||
for element in iterable: | ||
else: | ||
Comment on lines
-219
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
k = key(element) | ||
if k not in seen: | ||
seen_add(k) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
|
||
try: | ||
print('Line 4') | ||
print(sum([i*i for i in range(100) if i&1 == 1]) | ||
) | ||
print(sum(i*i for i in range(100) if i&1 == 1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -34,8 +33,7 @@ | |
|
||
try: | ||
print('Line 23') | ||
print(sum([i*i for i in range(100)]) | ||
) | ||
print(sum(i**2 for i in range(100))) | ||
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
@@ -52,7 +50,7 @@ | |
|
||
try: | ||
def frange(n): | ||
return [i for i in range(n)] | ||
return list(range(n)) | ||
Comment on lines
-55
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -83,8 +81,7 @@ def frange(n): | |
|
||
try: | ||
def grange(n): | ||
for x in [i for i in range(n)]: | ||
yield x | ||
yield from list(range(n)) | ||
Comment on lines
-86
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except Exception as __e: | ||
print("Occurred", type(__e), __e) | ||
|
||
|
@@ -233,7 +230,7 @@ def test_func(): | |
|
||
try: | ||
def test_func(): | ||
items = [(lambda: y) for i in range(5)] | ||
items = [lambda: y for _ in range(5)] | ||
Comment on lines
-236
to
+233
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
y = 2 | ||
return [x() for x in items] | ||
except Exception as __e: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
C.setx
refactored with the following changes:min-max-identity
)