Skip to content
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

Open
wants to merge 1 commit into
base: CPython37
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doctest_generated/test_descrtut.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def getx(self):
return self.__x

def setx(self, x):
if x < 0: x = 0
x = max(x, 0)
Copy link
Author

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:

self.__x = x

x = property(getx, setx)
Expand Down Expand Up @@ -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)
Copy link
Author

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:

self.__x = x
x = property(getx, setx)
#
Expand Down
97 changes: 29 additions & 68 deletions doctest_generated/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

try:
def firstn(g, n):
return [next(g) for i in range(n)]
return [next(g) for _ in range(n)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function firstn refactored with the following changes:

#
def intsfrom(i):
while 1:
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sieve refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

#
except Exception as __e:
print("Occurred", type(__e), __e)
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function m235 refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

#
# Don't print "too many" of these -- the implementation above is extremely
# inefficient: each call of m235() leads to 3 recursive calls, and in
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function m235 refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

#
# Print as many of these as you like -- *this* implementation is memory-
# efficient.
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fibgen.tail refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)


yield a
yield b
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function m235._m235 refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

m1 = _m235()
m2, m3, m5, mRes = tee(m1, 4)
return mRes
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fib._fib refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)


realfib = _fib()
fibHead, fibTail, fibRes = tee(realfib, 3)
Expand Down Expand Up @@ -450,8 +444,7 @@ def gencopy(iterator):

try:
def g():
i = next(me)
yield i
yield next(me)
Comment on lines -453 to +447
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function g refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function inorder refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

#
except Exception as __e:
print("Occurred", type(__e), __e)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function g refactored with the following changes:

yield None
yield None
return
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gcomb refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

#
except Exception as __e:
print("Occurred", type(__e), __e)
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function disjointSet.generate refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)


def find(self):
return next(self.generator)
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

finally:
pass
#
Expand Down Expand Up @@ -976,8 +964,7 @@ def f():

try:
def f():
if 0:
yield
pass
Comment on lines -979 to +967
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand All @@ -993,8 +980,7 @@ def f():

try:
def f():
if 0:
yield 1
pass
Comment on lines -996 to +983
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand All @@ -1010,8 +996,7 @@ def f():

try:
def f():
if "":
yield None
pass
Comment on lines -1013 to +999
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

This removes the following comments ( why? ):

# don't blink

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -1101,10 +1067,7 @@ def f(self):

try:
def f():
if 0:
return
if 0:
yield 2
pass
Comment on lines -1104 to +1070
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -1315,7 +1278,6 @@ def f():
def f():
yield 1
return
yield 2 # never reached
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

This removes the following comments ( why? ):

# never reached

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function yrange refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function zrange refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function f refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down
16 changes: 6 additions & 10 deletions doctest_generated/test_genexps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 13-78 refactored with the following changes:


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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function zrange refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down
7 changes: 3 additions & 4 deletions doctest_generated/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function unique_everseen refactored with the following changes:

k = key(element)
if k not in seen:
seen_add(k)
Expand Down
13 changes: 5 additions & 8 deletions doctest_generated/test_listcomps.py
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))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 4-38 refactored with the following changes:


except Exception as __e:
print("Occurred", type(__e), __e)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function frange refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function grange refactored with the following changes:

except Exception as __e:
print("Occurred", type(__e), __e)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_func refactored with the following changes:

y = 2
return [x() for x in items]
except Exception as __e:
Expand Down
Loading