Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 1, 2022

Branch master 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 master branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from drts01 March 1, 2022 23:48
parser.add_argument('name', help='Name to greet')
args = parser.parse_args()
print('Hello, ' + args.name + '!')
print(f'Hello, {args.name}!')
Copy link
Author

Choose a reason for hiding this comment

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

Lines 9-9 refactored with the following changes:

default='World', help='Name to greet')
args = parser.parse_args()
print('Hello, ' + args.name + '!')
print(f'Hello, {args.name}!')
Copy link
Author

Choose a reason for hiding this comment

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

Lines 10-10 refactored with the following changes:

default='World', help='Name to greet')
args = parser.parse_args()
print('Hello, ' + args.name + '!')
print(f'Hello, {args.name}!')
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

def main():
args = get_args()
print('Hello, ' + args.name + '!')
print(f'Hello, {args.name}!')
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:


args = get_args()
print('Hello, ' + args.name + '!')
print(f'Hello, {args.name}!')
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -47 to +57
pattern = (
'([' + consonants + ']+)?' # capture one or more, optional
'([' + vowels + '])' # capture at least one vowel
'(.*)' # capture zero or more of anything
)
pattern = (((f'([{consonants}' + ']+)?' # capture one or more, optional
'([') + vowels) + '])' # capture at least one vowel
'(.*)')
pattern = f'([{consonants}]+)?([{vowels}])(.*)'

match = re.match(pattern, word)
if match:
p1 = match.group(1) or ''
p2 = match.group(2) or ''
p3 = match.group(3) or ''
return (p1, p2 + p3)
else:
if not (match := re.match(pattern, word)):
return (word, '')
p1 = match.group(1) or ''
p2 = match.group(2) or ''
p3 = match.group(3) or ''
return (p1, p2 + p3)
Copy link
Author

Choose a reason for hiding this comment

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

Function stemmer refactored with the following changes:

This removes the following comments ( why? ):

# capture zero or more of anything

Comment on lines -42 to +44
vowel_pos = list(map(word.index, filter(lambda v: v in word, 'aeiou')))

if vowel_pos:
if vowel_pos := list(
map(word.index, filter(lambda v: v in word, 'aeiou'))
):
Copy link
Author

Choose a reason for hiding this comment

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

Function stemmer refactored with the following changes:

Comment on lines -44 to +47
if word.endswith('ing'):
if any(map(lambda c: c.lower() in 'aeiouy', word[:-3])):
return word[:-1] + "'"
if word.endswith('ing') and any(
map(lambda c: c.lower() in 'aeiouy', word[:-3])
):
return word[:-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 fry refactored with the following changes:


assert os.path.isfile(file)
expected_file = file + '.out'
expected_file = f'{file}.out'
Copy link
Author

Choose a reason for hiding this comment

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

Function run_file refactored with the following changes:

article = 'an' if pos.lower()[0] in 'aeiou' else 'a'
answer = inputs.pop(0) if inputs else input(tmpl.format(article, pos))
text = text[0:start] + answer + text[stop + 1:]
text = text[:start] + answer + text[stop + 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 main refactored with the following changes:

if name and reps:
match = re.match(r'(\d+)-(\d+)', reps)
if match:
if match := re.match(r'(\d+)-(\d+)', reps):
Copy link
Author

Choose a reason for hiding this comment

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

Function read_csv refactored with the following changes:

for rec in reader:
records.append(rec)

records = list(reader)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 8-11 refactored with the following changes:

Comment on lines -72 to +75
cells = []
for i, char in enumerate(board, start=1):
cells.append(str(i) if char == '.' else char)
cells = [
str(i) if char == '.' else char
for i, char in enumerate(board, start=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 format_board refactored with the following changes:


losing_board = list('XXOO.....')
for i in range(10):
for _ in range(10):
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_losing refactored with the following changes:

Comment on lines -66 to +68
for i in range(10):
for _ in range(10):
random.shuffle(losing_state)
assert find_winner(''.join(losing_state)) == None
assert find_winner(''.join(losing_state)) is None
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_losing refactored with the following changes:

rv, out = getstatusoutput(f'{prg} "{word}"')
assert rv == 0
assert out == f'input is space.'
assert out == 'input is space.'
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_space refactored with the following changes:

Comment on lines -111 to +116
out_file, out_arg = (random_file,
'-o ' + random_file) if flip == 1 else ('out.txt',
'')
out_file, out_arg = (
(random_file, f'-o {random_file}')
if flip == 1
else ('out.txt', '')
)

Copy link
Author

Choose a reason for hiding this comment

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

Function run refactored with the following changes:

"""runs on good input"""

out_file = random_string() + '.fasta'
out_file = f'{random_string()}.fasta'
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_options refactored with the following changes:

Comment on lines -68 to -76
out_fh = open(out_file, 'wt')
num_taken = 0
with open(out_file, 'wt') as out_fh:
num_taken = 0

for rec in SeqIO.parse(fh, 'fasta'):
if random.random() <= args.pct:
num_taken += 1
SeqIO.write(rec, out_fh, 'fasta')
for rec in SeqIO.parse(fh, 'fasta'):
if random.random() <= args.pct:
num_taken += 1
SeqIO.write(rec, out_fh, 'fasta')

out_fh.close()
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -126 to +129
seqs_written = 0
for file in files:
seqs_written += len(
list(SeqIO.parse(os.path.join(out_dir, file), 'fasta')))
seqs_written = sum(
len(list(SeqIO.parse(os.path.join(out_dir, file), 'fasta')))
for file in files
)
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_options refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 1, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.07%.

Quality metrics Before After Change
Complexity 2.01 ⭐ 1.90 ⭐ -0.11 👍
Method Length 35.80 ⭐ 35.69 ⭐ -0.11 👍
Working memory 5.97 ⭐ 6.05 ⭐ 0.08 👎
Quality 81.91% 81.84% -0.07% 👎
Other metrics Before After Change
Lines 1992 1976 -16
Changed files Quality Before Quality After Quality Change
01_hello/hello04_argparse_positional.py 93.85% ⭐ 93.85% ⭐ 0.00%
01_hello/hello05_argparse_option.py 90.40% ⭐ 90.40% ⭐ 0.00%
01_hello/hello06_main_function.py 92.86% ⭐ 92.86% ⭐ 0.00%
01_hello/hello07_get_args.py 95.02% ⭐ 95.02% ⭐ 0.00%
01_hello/hello08_formatted.py 96.21% ⭐ 96.21% ⭐ 0.00%
03_picnic/solution.py 81.97% ⭐ 81.87% ⭐ -0.10% 👎
04_jump_the_five/solution2.py 90.51% ⭐ 90.31% ⭐ -0.20% 👎
04_jump_the_five/solution3.py 90.08% ⭐ 90.31% ⭐ 0.23% 👍
07_gashlycrumb/solution1.py 83.61% ⭐ 83.58% ⭐ -0.03% 👎
11_bottles_of_beer/solution.py 88.32% ⭐ 88.36% ⭐ 0.04% 👍
12_ransom/solution1_for_loop.py 90.58% ⭐ 90.25% ⭐ -0.33% 👎
12_ransom/solution3_for_append_string.py 90.66% ⭐ 90.15% ⭐ -0.51% 👎
13_twelve_days/solution.py 83.52% ⭐ 83.47% ⭐ -0.05% 👎
13_twelve_days/solution_emoji.py 83.44% ⭐ 83.39% ⭐ -0.05% 👎
13_twelve_days/test.py 81.19% ⭐ 81.19% ⭐ 0.00%
14_rhymer/solution1_regex.py 83.35% ⭐ 84.02% ⭐ 0.67% 👍
14_rhymer/solution2_no_regex.py 90.34% ⭐ 89.82% ⭐ -0.52% 👎
15_kentucky_friar/solution3_no_regex.py 89.50% ⭐ 90.12% ⭐ 0.62% 👍
15_kentucky_friar/test.py 92.76% ⭐ 92.73% ⭐ -0.03% 👎
17_mad_libs/solution2_no_regex.py 66.85% 🙂 66.92% 🙂 0.07% 👍
19_wod/solution2.py 72.22% 🙂 71.10% 🙂 -1.12% 👎
19_wod/using_csv1.py 87.17% ⭐ 89.16% ⭐ 1.99% 👍
21_tictactoe/solution2.py 75.47% ⭐ 75.01% ⭐ -0.46% 👎
21_tictactoe/test.py 86.78% ⭐ 86.78% ⭐ 0.00%
22_itictactoe/unit.py 81.48% ⭐ 81.48% ⭐ 0.00%
appendix_argparse/one_arg.py 94.90% ⭐ 94.90% ⭐ 0.00%
bin/new.py 71.72% 🙂 70.91% 🙂 -0.81% 👎
extra/02_strings/test.py 90.55% ⭐ 90.57% ⭐ 0.02% 👍
extra/07_proteins/test.py 87.88% ⭐ 87.84% ⭐ -0.04% 👎
extra/09_moog/test.py 69.27% 🙂 69.24% 🙂 -0.03% 👎
extra/10_whitmans/solution.py 61.42% 🙂 61.98% 🙂 0.56% 👍
extra/10_whitmans/test.py 78.03% ⭐ 78.77% ⭐ 0.74% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
extra/09_moog/test.py test_options 2 ⭐ 209 ⛔ 14 😞 49.14% 😞 Try splitting into smaller methods. Extract out complex expressions
17_mad_libs/solution2_no_regex.py main 9 🙂 120 😞 15 😞 49.72% 😞 Try splitting into smaller methods. Extract out complex expressions
extra/10_whitmans/solution.py main 8 ⭐ 133 😞 14 😞 50.35% 🙂 Try splitting into smaller methods. Extract out complex expressions
21_tictactoe/solution2.py get_args 5 ⭐ 137 😞 9 🙂 61.45% 🙂 Try splitting into smaller methods
bin/new.py get_defaults 11 🙂 60 ⭐ 10 😞 64.29% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

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