Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Apr 24, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from eo1989 April 24, 2023 18:02
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -255 to +264
build_if_needed(pylit, f.with_suffix(f.suffix+'.txt'), f)
build_if_needed(pylit, f.with_suffix(f'{f.suffix}.txt'), f)
for f in files_py
]
for item in txt_builds:
logger.info(item)

index_build = build_if_needed(
make_index, Path("index.txt"),
*[f.with_suffix(f.suffix+'.txt') for f in files_py]
make_index,
Path("index.txt"),
*[f.with_suffix(f'{f.suffix}.txt') for f in files_py],
Copy link
Author

Choose a reason for hiding this comment

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

Function make_files refactored with the following changes:

if k < 2:
return 1
return reduce(operator.mul, range(2,k+1))
return 1 if k < 2 else reduce(operator.mul, range(2,k+1))
Copy link
Author

Choose a reason for hiding this comment

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

Function fact refactored with the following changes:

Comment on lines -124 to +129
term = ((-1)**k/fact(k))*(z**(s+k)/(s+k))
yield term

T_ = TypeVar("T_")
yield ((-1)**k/fact(k))*(z**(s+k)/(s+k))

T_ = TypeVar("T_")
def take_until(function: Callable[[T_], bool], source: Iterable[T_]) -> Iterator[T_]:
for v in source:
if function(v): return
yield v

Copy link
Author

Choose a reason for hiding this comment

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

Function gamma refactored with the following changes:

Comment on lines -501 to +502
if abs(k-int(k)-.5) < ε:
n = int(k-.5)
return fact(2*n)/(4**n*fact(n))*math.sqrt(math.pi)
else:
if abs(k - int(k) - 0.5) >= ε:
return float(Gamma2(k))
n = int(k-.5)
return fact(2*n)/(4**n*fact(n))*math.sqrt(math.pi)
Copy link
Author

Choose a reason for hiding this comment

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

Function Gamma_Half refactored with the following changes:

if n % 3 == 0 or n % 5 == 0:
s += n
return s
return sum(n for n in range(1, limit) if n % 3 == 0 or n % 5 == 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 sum_numeric refactored with the following changes:

Comment on lines -138 to +141
if n < 2:
if n < 2 or n != 2 and n % 2 == 0:
return False
elif n == 2:
return True
elif n % 2 == 0:
return False
else:
for i in range(3, 1 + int(math.sqrt(n)), 2):
if n % i == 0:
return False
return True
return all(n % i != 0 for i in range(3, 1 + int(math.sqrt(n)), 2))
Copy link
Author

Choose a reason for hiding this comment

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

Function isprimei refactored with the following changes:

Comment on lines -189 to +182
return not any(n % p == 0 for p in range(3, int(math.sqrt(n)) + 1, 2))
return all(n % p != 0 for p in range(3, int(math.sqrt(n)) + 1, 2))
Copy link
Author

Choose a reason for hiding this comment

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

Function isprimeg refactored with the following changes:

Comment on lines -404 to +401
if len(line.strip()) == 0:
return source, source.readline()
return strip_head(source, source.readline())
return (
strip_head(source, source.readline())
if line.strip()
else (source, source.readline())
)
Copy link
Author

Choose a reason for hiding this comment

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

Function strip_head refactored with the following changes:

Comment on lines -435 to +440
for repeat in range(1000):
for _ in range(1000):
assert all(isprimei(x) for x in primes)
print(f"all() {time.perf_counter() - start:.3f}")

start = time.perf_counter()
for repeat in range(1000):
assert not any(not isprimei(x) for x in primes)
for _ in range(1000):
assert all(isprimei(x) for x in primes)
print(f"not any() {time.perf_counter() - start:.3f}")

start = time.perf_counter()
for repeat in range(1000):
for _ in range(1000):
Copy link
Author

Choose a reason for hiding this comment

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

Function performance refactored with the following changes:

if b == 0:
return 1
return 2 * multy(b - 1)
return 1 if b == 0 else 2 * multy(b - 1)
Copy link
Author

Choose a reason for hiding this comment

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

Function multy refactored with the following changes:

assert faster(17) - 1 == 131071
assert shifty(17) == 131072
assert multy(17) == 131072
assert faster(17) == 131072
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_mults refactored with the following changes:

if chars:
return remove(text.replace(chars[0], ""), chars[1:])
return text
return remove(text.replace(chars[0], ""), chars[1:]) if chars else text
Copy link
Author

Choose a reason for hiding this comment

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

Function remove refactored with the following changes:

Comment on lines -52 to +50
if text is None:
return None
return Decimal(remove(text, "$,"))
return None if text is None else Decimal(remove(text, "$,"))
Copy link
Author

Choose a reason for hiding this comment

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

Function clean_decimal_3 refactored with the following changes:


def factor_n(x: int, n: int) -> Iterator[int]:
if n * n > x:
if n**2 > x:
Copy link
Author

Choose a reason for hiding this comment

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

Function pfactorsr refactored with the following changes:

try:
data_f = float(data)
return data_f
return float(data)
Copy link
Author

Choose a reason for hiding this comment

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

Function float_none refactored with the following changes:

z_2 = (z(x, m_2, s_2) for x in samples2)
r = sum(zx1 * zx2 for zx1, zx2 in zip(z_1, z_2)) / len(samples1)
return r
return sum(zx1 * zx2 for zx1, zx2 in zip(z_1, z_2)) / len(samples1)
Copy link
Author

Choose a reason for hiding this comment

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

Function corr refactored with the following changes:

for line in data:
for x in line:
yield x
yield from line
Copy link
Author

Choose a reason for hiding this comment

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

Function flatten refactored with the following changes:

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

Comment on lines -154 to +157
if len(line.strip()) == 0:
return source, source.readline()
return strip_head(source, source.readline())
return (
strip_head(source, source.readline())
if line.strip()
else (source, source.readline())
)
Copy link
Author

Choose a reason for hiding this comment

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

Function strip_head refactored with the following changes:

Comment on lines -227 to +232
full_sized_items = list(
tuple(next(flat_iter) for i in range(n)) for row in range(len(sequence) // n)
)
trailer = tuple(flat_iter)
if trailer:
full_sized_items = [
tuple(next(flat_iter) for _ in range(n))
for _ in range(len(sequence) // n)
]
if trailer := tuple(flat_iter):
Copy link
Author

Choose a reason for hiding this comment

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

Function group_by_seq refactored with the following changes:

return b
else:
return add(a - 1, b + 1)
return b if a == 0 else add(a - 1, b + 1)
Copy link
Author

Choose a reason for hiding this comment

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

Function add refactored with the following changes:

Comment on lines -20 to +17
if n == 0:
return 1
else:
return n * fact(n - 1)
return 1 if n == 0 else n * fact(n - 1)
Copy link
Author

Choose a reason for hiding this comment

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

Function fact refactored with the following changes:

Comment on lines -65 to +59
n = n - 1
n -= 1
Copy link
Author

Choose a reason for hiding this comment

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

Function fasts refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

Comment on lines -105 to -106
else: # Ignore other filesystem objects
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function all_print refactored with the following changes:

This removes the following comments ( why? ):

# Ignore other filesystem objects

Comment on lines -134 to +126
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
return 1 if n == 1 else fib(n - 1) + fib(n - 2)
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 refactored with the following changes:

Comment on lines -240 to +231
else:
q, r = divmod(n, 2)
if r == 1:
return a * fastexp_w(a, n - 1)
else:
return (t := fastexp_w(a, q)) * t
q, r = divmod(n, 2)
return a * fastexp_w(a, n - 1) if r == 1 else (t := fastexp_w(a, q)) * t
Copy link
Author

Choose a reason for hiding this comment

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

Function fastexp_w refactored with the following changes:

if n % 2 == 0:
return n // 2
return 3 * n + 1
return n // 2 if n % 2 == 0 else 3 * n + 1
Copy link
Author

Choose a reason for hiding this comment

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

Function syracuse refactored with the following changes:

return dict(group(quantized))
except StopIteration:
return dict()
return {}
Copy link
Author

Choose a reason for hiding this comment

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

Function group_sort refactored with the following changes:

Comment on lines -34 to +36
pairs: Callable[[RawPairIter], list[Pair]] = lambda source: list(
pairs: Callable[[RawPairIter], list[Pair]] = lambda source: [
Pair(*row) for row in source
)
]
Copy link
Author

Choose a reason for hiding this comment

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

Lines 34-36 refactored with the following changes:

Comment on lines -187 to +190
sorted_iter: Iterator[tuple[BaseT, ...]],
base: int,
same_rank_list: list[tuple[BaseT, ...]],
) -> Iterator[tuple[float, tuple[BaseT, ...]]]:
sorted_iter: Iterator[tuple[BaseT, ...]],
base: int,
same_rank_list: list[tuple[BaseT, ...]],
) -> Iterator[tuple[float, tuple[BaseT, ...]]]:
Copy link
Author

Choose a reason for hiding this comment

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

Function rank2_rec refactored with the following changes:

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

Comment on lines -225 to +233
data = list(Ranked_XY(rank=pmap(), raw=p) for p in pairs)
data = [Ranked_XY(rank=pmap(), raw=p) for p in pairs]

for attribute_name in ("x", "y"):
ranked = rank(data, lambda rxy: cast(float, getattr(rxy.raw, attribute_name)))
data = list(
data = [
original.set(
rank=original.rank.set(attribute_name, r) # type: ignore [arg-type]
)
for r, original in ranked
)
]
Copy link
Author

Choose a reason for hiding this comment

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

Function rank_xy refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant