-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
|
||
# 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) |
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 fibonacci
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
# 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) |
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 fibonacci_lru
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
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 | |||
''' | |||
|
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.
Lines 22-22
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
@@ -1,5 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
"""""" | |||
|
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.
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 -*- | |||
"""""" | |||
|
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.
Lines 22-72
refactored with the following changes:
- Replace list() with [] (
list-literal
) - Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
This removes the following comments ( why? ):
# To add more items
return "{} is now dancing".format(self.name) | ||
return f"{self.name} is now dancing" |
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 Parrot.dance
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
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") |
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 main
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
print("Selling Price: {}".format(self.__maxprice)) | ||
print(f"Selling Price: {self.__maxprice}") |
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 Computer.sell
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
self.sides = [0 for i in range(no_of_sides)] | ||
self.sides = [0 for _ in range(no_of_sides)] |
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 Polygon.__init__
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
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)] |
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 Polygon.inputSides
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.83%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
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:Help us improve this pull request!