Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 30, 2020

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^

Comment on lines -56 to +57
for i in range(len(messages)):
msg = messages[i]
for message in messages:
msg = message
Copy link
Author

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)
Copy link
Author

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)

Comment on lines -1028 to +1047
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))
Copy link
Author

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)

Comment on lines -1066 to +1067
if nbytes == None:
if nbytes 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 DedupFS.__report_throughput refactored with the following changes:

  • Use x is None rather than x == None (none-compare)

Comment on lines +1082 to +1084
if not self.logger.isEnabledFor(logging.DEBUG):
return
printed_header = False
Copy link
Author

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)

Comment on lines -144 to +146
opta = []
for o, v in self.optdict.iteritems():
opta.append(o + '=' + v)
opta = [o + '=' + v for o, v in self.optdict.iteritems()]
Copy link
Author

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:
Copy link
Author

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:
Copy link
Author

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
Copy link
Author

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)

Comment on lines -731 to +733
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(),
}
Copy link
Author

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-ai
Copy link
Author

sourcery-ai bot commented Jun 30, 2020

Sourcery Code Quality Report (beta)

✅ Merging this PR will increase code quality in the affected files by 0.02 out of 10.

Before After Change
Quality 8.42 8.44 0.02
Complexity 4.18 4.03 -0.16
Method Length 54.91 54.69 -0.22
Lines 1679 1679 0
Changed files Quality Before Quality After Quality Change
download_service.py 8.47 8.49 0.02 ⬆️
telegram_client_x.py 7.12 7.12 0.0 ⬆️
dedupfs/dedupfs.py 8.42 8.43 0.01 ⬆️
dedupfs/fuse.py 8.68 8.7 0.02 ⬆️

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

File Function Quality Recommendation
telegram_client_x.py TelegramClientX.upload_file 1.17 Split out functionality. Reduce complexity
telegram_client_x.py TelegramClientX.download_file 1.61 Split out functionality. Reduce complexity
dedupfs/fuse.py feature_needs 2.97 Split out functionality
dedupfs/dedupfs.py DedupFS.__write_blocks 4.18 Split out functionality
dedupfs/fuse.py feature_needs.resolve 4.6 Split out functionality

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!

Let us know what you think of it via email or our Gitter!

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