-
Notifications
You must be signed in to change notification settings - Fork 83
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 master branch #29
base: master
Are you sure you want to change the base?
Conversation
for i in range(len(messages)): | ||
msg = messages[i] | ||
for message in messages: | ||
msg = message |
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 download_block
refactored with the following changes:
- Replace index in for loop with direct reference (
for-index-replacement
)
if isinstance(file, str): | ||
file_name = os.path.basename(file) | ||
else: | ||
file_name = str(file_id) | ||
|
||
file_name = os.path.basename(file) if isinstance(file, str) else str(file_id) |
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 TelegramClientX.upload_file
refactored with the following changes:
- Swap positions of nested conditionals (
swap-nested-ifs
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Replace if statement with if expression (
assign-if-exp
)
if self.logger.isEnabledFor(logging.DEBUG): | ||
timings = [(self.time_spent_traversing_tree, 'Traversing the tree'), | ||
(self.time_spent_caching_nodes, 'Caching tree nodes'), | ||
(self.time_spent_interning, 'Interning path components'), | ||
(self.time_spent_writing_blocks, 'Writing data blocks'), | ||
(self.time_spent_hashing, 'Hashing data blocks'), | ||
(self.time_spent_querying_tree, 'Querying the tree')] | ||
maxdescwidth = max([len(l) for t, l in timings]) + 3 | ||
timings.sort(reverse=True) | ||
uptime = time.time() - self.fs_mounted_at | ||
printed_heading = False | ||
for timespan, description in timings: | ||
percentage = timespan / (uptime / 100) | ||
if percentage >= 1: | ||
if not printed_heading: | ||
self.logger.debug("Cumulative timings of slowest operations:") | ||
printed_heading = True | ||
self.logger.debug( | ||
" - %-*s%s (%i%%)" % (maxdescwidth, description + ':', format_timespan(timespan), percentage)) | ||
if not self.logger.isEnabledFor(logging.DEBUG): | ||
return | ||
timings = [(self.time_spent_traversing_tree, 'Traversing the tree'), | ||
(self.time_spent_caching_nodes, 'Caching tree nodes'), | ||
(self.time_spent_interning, 'Interning path components'), | ||
(self.time_spent_writing_blocks, 'Writing data blocks'), | ||
(self.time_spent_hashing, 'Hashing data blocks'), | ||
(self.time_spent_querying_tree, 'Querying the tree')] | ||
maxdescwidth = max(len(l) for t, l in timings) + 3 | ||
timings.sort(reverse=True) | ||
uptime = time.time() - self.fs_mounted_at | ||
printed_heading = False | ||
for timespan, description in timings: | ||
percentage = timespan / (uptime / 100) | ||
if percentage >= 1: | ||
if not printed_heading: | ||
self.logger.debug("Cumulative timings of slowest operations:") | ||
printed_heading = True | ||
self.logger.debug( | ||
" - %-*s%s (%i%%)" % (maxdescwidth, description + ':', format_timespan(timespan), percentage)) |
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 DedupFS.__report_timings
refactored with the following changes:
- Add guard clause (
last-if-guard
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
if nbytes == None: | ||
if nbytes 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 DedupFS.__report_throughput
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
if not self.logger.isEnabledFor(logging.DEBUG): | ||
return | ||
printed_header = False |
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 DedupFS.__report_top_blocks
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
) - Add guard clause (
last-if-guard
)
opta = [] | ||
for o, v in self.optdict.iteritems(): | ||
opta.append(o + '=' + v) | ||
opta = [o + '=' + v for o, v in self.optdict.iteritems()] |
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 FuseArgs.assemble
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
if not 'indent_increment' in kw: | ||
if 'indent_increment' not in kw: |
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 FuseFormatter.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if not 'dest' in attrs: | ||
if 'dest' not in attrs: |
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 FuseOptParse.add_option
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
for f in fp: | ||
yield f | ||
yield from fp |
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 feature_needs.resolve
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
) - Simplify logical expression using De Morgan identities (
de-morgan
)
d = {'multithreaded': self.multithreaded and 1 or 0} | ||
d['fuse_args'] = args or self.fuse_args.assemble() | ||
d = { | ||
'multithreaded': self.multithreaded and 1 or 0, | ||
'fuse_args': args or self.fuse_args.assemble(), | ||
} |
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 Fuse.main
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
Sourcery Code Quality Report (beta)✅ Merging this PR will increase code quality in the affected files by 0.02 out of 10.
Here are some functions in these files that still need a tune-up:
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! |
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: