Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 28, 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^

return False

return True
return all(num % i != 0 for i in range(2, num))
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_prime refactored with the following changes:

  • Use any() instead of for loop (use-any)
  • Invert any/all to simplify comparisons (invert-any-all)

Choose a reason for hiding this comment

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

Amazing!

def first_unique_character(s):
before = ''
for i in range(0, len(s)):
for i in range(len(s)):
Copy link
Author

Choose a reason for hiding this comment

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

Function first_unique_character refactored with the following changes:

  • Replace range(0, x) with range(x) (remove-zero-from-range)

return False

return True
return all(num % i != 0 for i in range(2, end))
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_prime refactored with the following changes:

  • Use any() instead of for loop (use-any)
  • Invert any/all to simplify comparisons (invert-any-all)

@app.task
def show(symbol, time_count):
for m in range(time_count):
for _ in range(time_count):
Copy link
Author

Choose a reason for hiding this comment

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

Function show refactored with the following changes:

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

Comment on lines -69 to +131
if (self.p1points==0):
if self.p1points == 0:
result = "Love"
if (self.p1points==1):
elif self.p1points == 1:
result = "Fifteen"
if (self.p1points==2):
elif self.p1points == 2:
result = "Thirty"
if (self.p1points==3):
elif self.p1points == 3:
result = "Forty"
result += "-All"
if (self.p1points==self.p2points and self.p1points>3):
result = "Deuce"

P1res = ""
P2res = ""
if (self.p1points > 0 and self.p2points==0):
if (self.p1points==1):
if self.p1points == 1:
P1res = "Fifteen"
if (self.p1points==2):
elif self.p1points == 2:
P1res = "Thirty"
if (self.p1points==3):
elif self.p1points == 3:
P1res = "Forty"

P2res = "Love"
result = P1res + "-" + P2res
if (self.p2points > 0 and self.p1points==0):
if (self.p2points==1):
if self.p2points == 1:
P2res = "Fifteen"
if (self.p2points==2):
elif self.p2points == 2:
P2res = "Thirty"
if (self.p2points==3):
elif self.p2points == 3:
P2res = "Forty"

P1res = "Love"
result = P1res + "-" + P2res


if (self.p1points>self.p2points and self.p1points < 4):
if (self.p1points==2):
if self.p1points == 2:
P1res="Thirty"
if (self.p1points==3):
elif self.p1points == 3:
P1res="Forty"
if (self.p2points==1):
if self.p2points == 1:
P2res="Fifteen"
if (self.p2points==2):
elif self.p2points == 2:
P2res="Thirty"
result = P1res + "-" + P2res
if (self.p2points>self.p1points and self.p2points < 4):
if (self.p2points==2):
if self.p2points == 2:
P2res="Thirty"
if (self.p2points==3):
elif self.p2points == 3:
P2res="Forty"
if (self.p1points==1):
if self.p1points == 1:
P1res="Fifteen"
if (self.p1points==2):
elif self.p1points == 2:
P1res="Thirty"
result = P1res + "-" + P2res

if (self.p1points > self.p2points and self.p2points >= 3):
result = "Advantage " + self.player1Name

if (self.p2points > self.p1points and self.p1points >= 3):
result = "Advantage " + self.player2Name

Copy link
Author

Choose a reason for hiding this comment

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

Function TennisGameDefactored2.score refactored with the following changes:

  • Simplify conditional into switch-like form (switch)


def SetP1Score(self, number):
for i in range(number):
for _ in range(number):
Copy link
Author

Choose a reason for hiding this comment

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

Function TennisGameDefactored2.SetP1Score refactored with the following changes:

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


def SetP2Score(self, number):
for i in range(number):
for _ in range(number):
Copy link
Author

Choose a reason for hiding this comment

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

Function TennisGameDefactored2.SetP2Score refactored with the following changes:

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

Comment on lines -49 to +51
for i in range(p1_points):
for _ in range(p1_points):
game.won_point(p1_name)
for i in range(p2_points):
for _ in range(p2_points):
Copy link
Author

Choose a reason for hiding this comment

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

Function test_get_score refactored with the following changes:

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

def test_player_names():
game = TennisGame('One', 'Two')
for i in range(4):
for _ in range(4):
Copy link
Author

Choose a reason for hiding this comment

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

Function test_player_names refactored with the following changes:

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

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jun 28, 2020

Sourcery Code Quality Report (beta)

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

Before After Change
Quality 9.19 9.22 0.03
Complexity 2.0 1.63 -0.37
Method Length 28.69 28.49 -0.2
Lines 475 458 -17
Changed files Quality Before Quality After Quality Change
2016/201612_tdd_workshop/leap_year.py 9.67 9.68 0.02 ⬆️
2017/20170814_tdd_workshop/solutions/fizzbuzzwhiz.py 9.3 9.33 0.04 ⬆️
2017/future/first_unique_character_solution.py 9.53 9.53 0.01 ⬆️
2017/future/prime_numbers_solution.py 9.49 9.53 0.05 ⬆️
2018/20181019_talks/Celery Schedule Strategy/tasks.py 9.46 9.46 0.0
2019/201903_AI_school_meetup/coding_workshop.py 9.08 9.1 0.02 ⬆️
2019/201904_mob_programming_workshop/odd_even_prime.py 9.44 9.48 0.04 ⬆️
2020/202001_refactoring_workshop/fizzbuzzwhiz.py 9.35 9.4 0.05 ⬆️
2020/202001_refactoring_workshop/tennis_before.py 8.39 8.42 0.03 ⬆️
2020/202001_refactoring_workshop/tennis_test.py 7.75 7.75 0.0

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

File Function Quality Recommendation
2020/202001_refactoring_workshop/tennis_before.py TennisGameDefactored2.score 1.73 Split out functionality. Reduce complexity
2020/202001_refactoring_workshop/tennis_test.py test_get_score 6.22 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.

2 participants