-
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
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
n = int(n) | ||
n = 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 solution
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Replace assignment with augmented assignment (
aug-assign
)
print('The area of the triangle is: ' + area) | ||
print(f'The area of the triangle is: {area}') |
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 17-17
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for char in xnumber[len(xnumber ) -1]: | ||
if int(char) >= int(xbase): | ||
return False | ||
return True | ||
return all(int(char) < int(xbase) for char in xnumber[len(xnumber ) -1]) |
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 base_check
refactored with the following changes:
- Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
if int(xbase) == 2 or int(xbase) == 4 or int(xbase) == 6 or int(xbase) == 8: | ||
if int(xbase) in {2, 4, 6, 8}: | ||
|
||
if xnumber == 0: | ||
return arr | ||
else: | ||
quotient = int(xnumber) // int(xbase) | ||
remainder = int(xnumber) % int(xbase) | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, base) | ||
quotient, remainder = divmod(int(xnumber), int(xbase)) | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, base) | ||
elif int(xbase) == 16: | ||
if int(xnumber) == 0: | ||
return arr | ||
else: | ||
quotient = int(xnumber) // int(xbase) | ||
remainder = int(xnumber) % int(xbase) | ||
if remainder > 9: | ||
if remainder == 10: remainder = 'A' | ||
if remainder == 11: remainder = 'B' | ||
if remainder == 12: remainder = 'C' | ||
if remainder == 13: remainder = 'D' | ||
if remainder == 14: remainder = 'E' | ||
if remainder == 15: remainder = 'F' | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, ybase) | ||
quotient, remainder = divmod(int(xnumber), int(xbase)) | ||
if remainder > 9: | ||
if remainder == 10: remainder = 'A' | ||
if remainder == 11: remainder = 'B' | ||
if remainder == 12: remainder = 'C' | ||
if remainder == 13: remainder = 'D' | ||
if remainder == 14: remainder = 'E' | ||
if remainder == 15: remainder = 'F' | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, ybase) |
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 convert_from_10
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Remove unnecessary else after guard condition [×2] (
remove-unnecessary-else
) - Simplify division expressions [×2] (
simplify-division
) - Use set when checking membership of a collection of literals (
collection-into-set
)
if percent == 100: | ||
charging_message = "Unplug your Charger" | ||
else: | ||
charging_message = "Charging" | ||
charging_message = "Unplug your Charger" if percent == 100 else "Charging" |
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 15-18
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
@@ -6,6 +6,7 @@ | |||
Credit to William J. Turkel and Adam Crymble for the word | |||
frequency code used below. I just merged the two ideas. | |||
""" | |||
|
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 311-314
refactored with the following changes:
- Replace call to format with f-string [×4] (
use-fstring-for-formatting
) - Remove unnecessary calls to
str()
from formatted values in f-strings [×3] (remove-str-from-fstring
)
return "Company : " + comp | ||
return f"Company : {comp}" |
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 CreditCard.company
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if 13 <= len(self.card_no) <= 19: | ||
message = "First check : Valid in terms of length." | ||
|
||
else: | ||
message = "First check : Check Card number once again it must be of 13 or 16 digits long." | ||
return message | ||
return ( | ||
"First check : Valid in terms of length." | ||
if 13 <= len(self.card_no) <= 19 | ||
else "First check : Check Card number once again it must be of 13 or 16 digits long." | ||
) |
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 CreditCard.first_check
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
sum_ += sum([eval(i) for i in str(double_it)]) | ||
sum_ += sum(eval(i) for i in str(double_it)) |
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 CreditCard.validate
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
) - Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
return "#CHECKSUM# : " + self.card_no[-1] | ||
return f"#CHECKSUM# : {self.card_no[-1]}" |
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 CreditCard.checksum
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
score = [] | ||
results = [] | ||
|
||
for div_tags in soup.find_all("div", attrs={"class": "cb-lv-scrs-col text-black"}): | ||
score.append(div_tags.text) | ||
for result in soup.find_all("div", attrs={"class": "cb-lv-scrs-col cb-text-complete"}): | ||
results.append(result.text) | ||
score = [ | ||
div_tags.text | ||
for div_tags in soup.find_all( | ||
"div", attrs={"class": "cb-lv-scrs-col text-black"} | ||
) | ||
] | ||
|
||
results = [ | ||
result.text | ||
for result in soup.find_all( | ||
"div", attrs={"class": "cb-lv-scrs-col cb-text-complete"} | ||
) | ||
] |
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 17-23
refactored with the following changes:
- Move assignment closer to its usage within a block [×2] (
move-assign-in-block
) - Convert for loop into list comprehension [×2] (
list-comprehension
)
print("Day on " + user_input + " is " + find_day(date)) | ||
print(f"Day on {user_input} is {find_day(date)}") |
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 28-28
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
w_num = w_num // 2 | ||
w_num //= 2 | ||
whole.reverse() | ||
|
||
i = 0 | ||
while i < len(whole): | ||
print(whole[i], end="") | ||
i += 1 | ||
i = 0 | ||
while i < len(fractional): | ||
print(fractional[i], end="") | ||
i += 1 | ||
for item_ in whole: | ||
print(item_, end="") | ||
for item in fractional: | ||
print(item, end="") |
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 dtbconverter
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
) - Replace while with for [×2] (
while-to-for
) - Replace index in for loop with direct reference [×2] (
for-index-replacement
)
else: | ||
if temp.data == key: | ||
self.head = temp.next | ||
temp = None | ||
if temp.data == key: | ||
self.head = temp.next | ||
temp = None |
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 Linked_List.Delete
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
while ptr2.next != Loop_node and ptr2.next != ptr1: | ||
while ptr2.next not in [ptr2, ptr1]: |
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 Linked_List.Remove_loop
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
File = open("Management.txt", "r") | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
File.close() | ||
|
||
with open("Management.txt", "r") as File: | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) |
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 add
refactored with the following changes:
- Use
with
when opening file to ensure closure [×2] (ensure-file-closed
)
File = open("Management.txt", "a", encoding="utf-8") | ||
temp1 = { | ||
"First_Name": [], | ||
"Last_Name": [], | ||
"Phone_num": [], | ||
"Room_Type": [], | ||
"Days": [], | ||
"Price": [], | ||
"Room": [], | ||
} | ||
File.write(str(temp1)) | ||
File.close() | ||
with open("Management.txt", "a", encoding="utf-8") as File: | ||
temp1 = { | ||
"First_Name": [], | ||
"Last_Name": [], | ||
"Phone_num": [], | ||
"Room_Type": [], | ||
"Days": [], | ||
"Price": [], | ||
"Room": [], | ||
} | ||
File.write(str(temp1)) |
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 132-143
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
File = open("Management.txt", "r") | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
File.close() | ||
|
||
with open("Management.txt", "r") as File: | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
dict_num = dictionary.get("Room") | ||
dict_len = len(dict_num) | ||
print("") | ||
if dict_len == 0: | ||
print("") | ||
print("There is no data in our database") | ||
print("") | ||
menu() | ||
else: | ||
print("") |
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 modify
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
File = open("Management.txt", "r") | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
File.close() | ||
|
||
with open("Management.txt", "r") as File: | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
dict_num = dictionary.get("Room") | ||
dict_len = len(dict_num) | ||
print("") | ||
if dict_len == 0: | ||
print("") | ||
print("There is no data in our database") | ||
print("") | ||
menu() | ||
else: | ||
print("") |
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 search
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
File = open("Management.txt", "r") | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
File.close() | ||
|
||
with open("Management.txt", "r") as File: | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
dict_num = dictionary.get("Room") | ||
dict_len = len(dict_num) | ||
print("") | ||
if dict_len == 0: | ||
print("") | ||
print("There is no data in our database") | ||
print("") | ||
menu() | ||
else: | ||
print("") |
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 remove
refactored with the following changes:
- Use
with
when opening file to ensure closure [×2] (ensure-file-closed
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
File = open("Management.txt", "r") | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) | ||
File.close() | ||
|
||
with open("Management.txt", "r") as File: | ||
string = File.read() | ||
string = string.replace("'", '"') | ||
dictionary = json.loads(string) |
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 view
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace assignment with augmented assignment (
aug-assign
)
return True if self.top == -1 else False | ||
return self.top == -1 |
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 Conversion.isEmpty
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if not self.isEmpty(): | ||
self.top -= 1 | ||
return self.array.pop() | ||
else: | ||
if self.isEmpty(): | ||
return "$" | ||
self.top -= 1 | ||
return self.array.pop() |
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 Conversion.pop
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
return True if a <= b else False | ||
return a <= b |
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 Conversion.notGreater
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if self.job in self.jobs: | ||
self.jobindex = self.jobs.index(self.job) | ||
else: | ||
self.jobindex = 0 | ||
self.jobindex = self.jobs.index(self.job) if self.job in self.jobs else 0 |
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 Scheduling.feasible
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
print("{} Folder Created".format(name)) | ||
print(f"{name} Folder Created") | ||
except WindowsError: | ||
print("{} Folder Exist".format(name)) | ||
print(f"{name} Folder Exist") | ||
|
||
src = "{}\\{}".format(destLocation, dirs) | ||
dest = "{}\{}".format(destLocation, name) | ||
src = f"{destLocation}\\{dirs}" | ||
dest = f"{destLocation}\{name}" | ||
|
||
os.chdir(dest) | ||
shutil.move(src, "{}\\{}".format(dest, dirs)) | ||
shutil.move(src, f"{dest}\\{dirs}") |
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 Organize
refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting
)
if 1: | ||
for name, extensions_list in zip( | ||
TYPES_LIST, | ||
[ | ||
EXT_VIDEO_LIST, | ||
EXT_IMAGE_LIST, | ||
EXT_DOCUMENT_LIST, | ||
EXT_MUSIC_LIST, | ||
EXT_CODE_LIST, | ||
EXT_EXECUTABLE_LIST, | ||
EXT_COMPRESSED_LIST, | ||
], | ||
): | ||
if dirs.split(".")[-1].upper() in extensions_list: | ||
Organize(dirs, name) | ||
else: | ||
if dirs not in TYPES_LIST: | ||
Organize(dirs, "Folders") | ||
|
||
for name, extensions_list in zip( | ||
TYPES_LIST, | ||
[ | ||
EXT_VIDEO_LIST, | ||
EXT_IMAGE_LIST, | ||
EXT_DOCUMENT_LIST, | ||
EXT_MUSIC_LIST, | ||
EXT_CODE_LIST, | ||
EXT_EXECUTABLE_LIST, | ||
EXT_COMPRESSED_LIST, | ||
], | ||
): | ||
if dirs.split(".")[-1].upper() in extensions_list: | ||
Organize(dirs, name) |
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 91-109
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
else: | ||
pass | ||
|
||
if ( | ||
ball_pos[1] <= (paddle2_pos + HEIGHT / 2 - PAD_HEIGHT / 2) | ||
or ball_pos[1] >= (paddle2_pos + PAD_HEIGHT / 2 + HEIGHT / 2) | ||
) and ball_pos[0] == (WIDTH - PAD_WIDTH - BALL_RADIUS): | ||
score1 += 1 | ||
else: | ||
pass | ||
|
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 draw
refactored with the following changes:
- Remove redundant pass statement [×2] (
remove-redundant-pass
)
if key == simplegui.KEY_MAP["down"] or key == simplegui.KEY_MAP["up"]: | ||
if key in [simplegui.KEY_MAP["down"], simplegui.KEY_MAP["up"]]: | ||
paddle1_vel = 0 | ||
if key == simplegui.KEY_MAP["w"] or key == simplegui.KEY_MAP["s"]: | ||
if key in [simplegui.KEY_MAP["w"], simplegui.KEY_MAP["s"]]: |
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 keyup
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator [×2] (merge-comparisons
)
for i in range(2, sqrt_n + 1): | ||
if n % i == 0: | ||
return False | ||
return True | ||
return all(n % i != 0 for i in range(2, sqrt_n + 1)) |
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 is_prime_a
refactored with the following changes:
- Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.40%.
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!