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 May 30, 2022

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^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from eniocc May 30, 2022 10:31
Comment on lines -34 to +39

# Compute the n-th term
if n == 0:
# Position 0
return 0
if n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
return 1 if n == 1 else fibonacci(n - 1) + fibonacci(n - 2)
Copy link
Author

Choose a reason for hiding this comment

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

Function fibonacci refactored with the following changes:

Comment on lines -104 to +112
# Now we will use the lru_cache from functools module. LRU means Least Recently Used Cache
# Look the following link for higher values of maxsize, https://stackoverflow.com/questions/5061582/setting-stacksize-in-a-python-script/16248113#16248113
def fibonacci_lru(n):
# Check that the input is a positive integer
if (type(n) != int):
raise TypeError("n must be a positive int")
if n < 0:
raise ValueError("n must be a positive int or zero")

# Compute the n-th term
if n == 0:
# Position 0
return 0
if n == 1:
return 1
else:
return fibonacci_lru(n - 1) + fibonacci_lru(n - 2)
return 1 if n == 1 else fibonacci_lru(n - 1) + fibonacci_lru(n - 2)
Copy link
Author

Choose a reason for hiding this comment

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

Function fibonacci_lru refactored with the following changes:

This removes the following comments ( why? ):

# Look the following link for higher values of maxsize, https://stackoverflow.com/questions/5061582/setting-stacksize-in-a-python-script/16248113#16248113
# Now we will use the lru_cache from functools module. LRU means Least Recently Used Cache

@@ -8,6 +8,7 @@
Based on Socratica videos
'''

Copy link
Author

Choose a reason for hiding this comment

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

Lines 22-22 refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""""""

Copy link
Author

Choose a reason for hiding this comment

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

Lines 44-45 refactored with the following changes:

  • Combine two compares on same value into a chained compare (chain-compares)

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
""""""

Copy link
Author

Choose a reason for hiding this comment

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

Lines 22-72 refactored with the following changes:

This removes the following comments ( why? ):

# To add more items

return "{} is now dancing".format(self.name)
return f"{self.name} is now dancing"
Copy link
Author

Choose a reason for hiding this comment

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

Function Parrot.dance refactored with the following changes:

Comment on lines -45 to +50
print("Blu is a {}".format(blu.__class__.species))
print("Woo is also a {}".format(woo.__class__.species))
print(f"Blu is a {blu.__class__.species}")
print(f"Woo is also a {woo.__class__.species}")

# access the instance attributes
print("{} is {} years old".format(blu.name, blu.age))
print("{} is {} years old".format(woo.name, woo.age))
print(f"{blu.name} is {blu.age} years old")
print(f"{woo.name} is {woo.age} years old")
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

print("Selling Price: {}".format(self.__maxprice))
print(f"Selling Price: {self.__maxprice}")
Copy link
Author

Choose a reason for hiding this comment

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

Function Computer.sell refactored with the following changes:

self.sides = [0 for i in range(no_of_sides)]
self.sides = [0 for _ in range(no_of_sides)]
Copy link
Author

Choose a reason for hiding this comment

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

Function Polygon.__init__ refactored with the following changes:

self.sides = [float(input("Enter side "+str(i+1)+" : "))
for i in range(self.n)]
self.sides = [float(input(f"Enter side {str(i+1)} : ")) for i in range(self.n)]
Copy link
Author

Choose a reason for hiding this comment

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

Function Polygon.inputSides refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented May 30, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.83%.

Quality metrics Before After Change
Complexity 2.69 ⭐ 2.33 ⭐ -0.36 👍
Method Length 64.32 🙂 63.59 🙂 -0.73 👍
Working memory 5.56 ⭐ 5.35 ⭐ -0.21 👍
Quality 70.54% 🙂 71.37% 🙂 0.83% 👍
Other metrics Before After Change
Lines 973 951 -22
Changed files Quality Before Quality After Quality Change
advanced/recursion_fibonacci_memoization.py 85.61% ⭐ 86.18% ⭐ 0.57% 👍
basics/arithmetic.py 77.78% ⭐ 78.03% ⭐ 0.25% 👍
basics/if_then_else.py 75.29% ⭐ 76.65% ⭐ 1.36% 👍
basics/lists_.py 58.89% 🙂 58.94% 🙂 0.05% 👍
basics/sets_.py 69.54% 🙂 70.28% 🙂 0.74% 👍
basics/text_files.py 75.67% ⭐ 76.05% ⭐ 0.38% 👍
basics/tuples_.py 47.07% 😞 50.27% 🙂 3.20% 👍
intermediate/exceptions_.py 86.22% ⭐ 86.80% ⭐ 0.58% 👍
intermediate/random_numbers.py 87.35% ⭐ 87.35% ⭐ 0.00%
objects_and_class/0_basics_.py 93.79% ⭐ 91.16% ⭐ -2.63% 👎
objects_and_class/1_encapsulation.py 98.81% ⭐ 98.81% ⭐ 0.00%
objects_and_class/5_inheritance_advanced.py 92.07% ⭐ 92.34% ⭐ 0.27% 👍

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

File Function Complexity Length Working Memory Quality Recommendation

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


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!

Help us improve this quality report!

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