-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #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
base: master
Are you sure you want to change the base?
Conversation
| parser.add_argument('name', help='Name to greet') | ||
| args = parser.parse_args() | ||
| print('Hello, ' + args.name + '!') | ||
| print(f'Hello, {args.name}!') |
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.
Lines 9-9 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| default='World', help='Name to greet') | ||
| args = parser.parse_args() | ||
| print('Hello, ' + args.name + '!') | ||
| print(f'Hello, {args.name}!') |
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.
Lines 10-10 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| default='World', help='Name to greet') | ||
| args = parser.parse_args() | ||
| print('Hello, ' + args.name + '!') | ||
| print(f'Hello, {args.name}!') |
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 main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| def main(): | ||
| args = get_args() | ||
| print('Hello, ' + args.name + '!') | ||
| print(f'Hello, {args.name}!') |
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 main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| args = get_args() | ||
| print('Hello, ' + args.name + '!') | ||
| print(f'Hello, {args.name}!') |
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 main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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) |
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 stemmer refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Use named expression to simplify assignment and conditional (
use-named-expression)
This removes the following comments ( why? ):
# capture zero or more of anything
| 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')) | ||
| ): |
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 stemmer refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| 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] + "'" |
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 fry refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
|
|
||
| assert os.path.isfile(file) | ||
| expected_file = file + '.out' | ||
| expected_file = f'{file}.out' |
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 run_file refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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:] |
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 main refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| if name and reps: | ||
| match = re.match(r'(\d+)-(\d+)', reps) | ||
| if match: | ||
| if match := re.match(r'(\d+)-(\d+)', reps): |
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 read_csv refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| for rec in reader: | ||
| records.append(rec) | ||
|
|
||
| records = list(reader) |
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.
Lines 8-11 refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
| 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) | ||
| ] |
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 format_board refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
|
|
||
| losing_board = list('XXOO.....') | ||
| for i in range(10): | ||
| for _ in range(10): |
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 test_losing refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| 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 |
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 test_losing refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Use x is None rather than x == None (
none-compare)
| rv, out = getstatusoutput(f'{prg} "{word}"') | ||
| assert rv == 0 | ||
| assert out == f'input is space.' | ||
| assert out == 'input is space.' |
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 test_space refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| 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', '') | ||
| ) | ||
|
|
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 run refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| """runs on good input""" | ||
|
|
||
| out_file = random_string() + '.fasta' | ||
| out_file = f'{random_string()}.fasta' |
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 test_options refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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() |
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 main refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| 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 | ||
| ) |
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 test_options refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.07%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!