-
Notifications
You must be signed in to change notification settings - Fork 0
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 main branch #1
base: main
Are you sure you want to change the base?
Conversation
string = '' | ||
i = 0 | ||
while i < 100: | ||
string += f'{random.randint(0,9)}' | ||
i += 1 | ||
|
||
string = ''.join(f'{random.randint(0, 9)}' for _ in range(100)) |
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 4-9
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Replace while with for (
while-to-for
) - Replace unused for index with underscore (
for-index-underscore
)
if i + 1 == target: | ||
end_point = length # Catch any left-over bytes in the last segment. | ||
else: | ||
end_point = (i + 1) * seg_size | ||
end_point = length if i + 1 == target else (i + 1) * seg_size | ||
slice = bytes[start_point:end_point] | ||
segments.append(slice) | ||
i += 1 | ||
|
||
checksums = [reduce(lambda acc, curr: acc ^ curr, segment) for segment in segments] | ||
|
||
|
||
return checksums No newline at end of file | ||
return [reduce(lambda acc, curr: acc ^ curr, segment) for segment in segments] |
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 compress
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Catch any left-over bytes in the last segment.
for word in words: | ||
styled_words.append(word.title()) | ||
styled_words.extend(word.title() for word in words) | ||
elif style == 'lowercase': | ||
for word in words: | ||
styled_words.append(word.lower()) | ||
styled_words.extend(word.lower() for word in words) | ||
elif style == 'uppercase': | ||
for word in words: | ||
styled_words.append(word.upper()) | ||
styled_words.extend(word.upper() for word in words) |
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 to_styled
refactored with the following changes:
- Replace a for append loop with list extend [×3] (
for-append-to-extend
)
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:Help us improve this pull request!