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 #1

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 Jul 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 -992 to +996
refs = set([r.strip() for r in refnames.strip("()").split(",")])
refs = {r.strip() for r in refnames.strip("()").split(",")}
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
tags = {r[len(TAG):] for r in refs if r.startswith(TAG)}
Copy link
Author

Choose a reason for hiding this comment

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

Function git_versions_from_keywords refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)
  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)

Comment on lines -1144 to +1148
if line.strip().startswith(versionfile_source):
if "export-subst" in line.strip().split()[1:]:
present = True
if (
line.strip().startswith(versionfile_source)
and "export-subst" in line.strip().split()[1:]
):
present = True
Copy link
Author

Choose a reason for hiding this comment

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

Function do_vcs_install refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

Comment on lines -1167 to +1169
for i in range(3):
for _ in range(3):
Copy link
Author

Choose a reason for hiding this comment

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

Function versions_from_parentdir refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

Comment on lines -1250 to +1257
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
if pieces["dirty"]:
rendered += ".dirty"
Copy link
Author

Choose a reason for hiding this comment

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

Function render_pep440 refactored with the following changes:

  • Hoist conditional out of nested conditional (hoist-if-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

Comment on lines -1316 to +1320
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
if pieces["dirty"]:
rendered += ".dev0"
Copy link
Author

Choose a reason for hiding this comment

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

Function render_pep440_old refactored with the following changes:

  • Hoist conditional out of nested conditional (hoist-if-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

Comment on lines -395 to +396
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
if pieces["dirty"]:
rendered += ".dev0"
Copy link
Author

Choose a reason for hiding this comment

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

Function render_pep440_old refactored with the following changes:

  • Hoist conditional out of nested conditional (hoist-if-from-if)
  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

msg = self.msg.format(**self.kwargs)
return msg
return self.msg.format(**self.kwargs)
Copy link
Author

Choose a reason for hiding this comment

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

Function ZiplineCalendarError.__str__ refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -853 to +854
if direction == "next":
if self._minute_to_session_label_cache[0] == dt:
return self._minute_to_session_label_cache[1]
if direction == "next" and self._minute_to_session_label_cache[0] == dt:
return self._minute_to_session_label_cache[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 TradingCalendar.minute_to_session_label refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

if dt.weekday() == SUNDAY or dt.weekday() == MONDAY:
if dt.weekday() in [SUNDAY, MONDAY]:
Copy link
Author

Choose a reason for hiding this comment

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

Function songkran_festival_last_day_observance refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)

Comment on lines -25 to +26
for h in holidays:
if dt in h.dates(dt - one_day, dt + one_day) or \
dt.weekday() in WEEKENDS:
return True

return False
return any(dt in h.dates(dt - one_day, dt + one_day) or \
dt.weekday() in WEEKENDS for h in holidays)
Copy link
Author

Choose a reason for hiding this comment

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

Function is_holiday_or_weekend refactored with the following changes:

  • Use any() instead of for loop (use-any)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 30, 2020

Sourcery Code Quality Report (beta)

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

Quality metrics Before After Change
Complexity 2.96 2.80 -0.16 🔵
Method Length 59.51 59.11 -0.40 🔵
Quality 8.53 8.55 0.02 🔵
Other metrics Before After Change
Lines 4155 4141 -14
Changed files Quality Before Quality After Quality Change
versioneer.py 7.78 7.81 0.03 🔵
tests/test_xhel_calendar.py 8.29 8.31 0.02 🔵
tests/test_xkar_calendar.py 8.09 8.09 0.00
trading_calendars/_version.py 7.78 7.84 0.06 🔵
trading_calendars/errors.py 9.66 9.68 0.02 🔵
trading_calendars/trading_calendar.py 9.25 9.25 0.00
trading_calendars/xbkk_holidays.py 8.52 8.56 0.04 🔵
trading_calendars/xtks_holidays.py 8.08 8.16 0.08 🔵

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

File Function Complexity Length Overall Recommendation
versioneer.py do_setup 21 287.67 3.55 Split out functionality
versioneer.py git_pieces_from_vcs 16 320.35 3.84 Split out functionality
versioneer.py get_cmdclass 13 445.61 3.84 Split out functionality
trading_calendars/_version.py git_pieces_from_vcs 16 320.35 3.84 Split out functionality
versioneer.py get_versions 20 215.70 4.14 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.

0 participants