-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
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.
elif not any(0 in row for row in self.matrix) and not self.horizontal_move_exists()\ | ||
and not self.vertical_move_exists(): | ||
elif ( | ||
all(0 not in row for row in self.matrix) | ||
and not self.horizontal_move_exists() | ||
and not self.vertical_move_exists() | ||
): |
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 Game.game_over
refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all
)
print(breaking * 10); | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
|
||
else: | ||
break; | ||
elif(c < a): | ||
print("error, number can't be smaller than min."); | ||
print("Wanna go again? y for yes and anykey for no. ") | ||
i = input(""); | ||
if(i == "y"): | ||
print(breaking * 10); | ||
print("now type in the number") | ||
c = int(input(" ")) | ||
tries = 1; | ||
if(a > b): | ||
print("error, min can't be more than max. ") | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
|
||
print("now type in the number") | ||
c = int(input(" ")) | ||
tries = 1; | ||
if(a > b): | ||
print("error, min can't be more than max. ") | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
print("now type in the number") | ||
c = int(input(" ")) | ||
else: | ||
d = random.randint(a, b) | ||
else: | ||
break; | ||
elif(d < c): | ||
a = d + 1; | ||
d = random.randint(a, b) | ||
print( "guess " + str(tries) + " :" + str(d)); | ||
tries += 1; | ||
else: | ||
d = random.randint(a, b) | ||
|
||
elif c > b: | ||
print("error, number can't be bigger than max."); | ||
print("Wanna go again? y for yes and anykey for no. ") | ||
i = input(""); | ||
if i != "y": | ||
break; | ||
print(breaking * 10); | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
|
||
print("now type in the number") | ||
c = int(input(" ")) | ||
tries = 1; | ||
if(a > b): | ||
(print("error, min can't be more than max. ")) | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
print("now type in the number") | ||
c = int(input(" ")) | ||
else: | ||
d = random.randint(a, b) | ||
|
||
elif c < a: | ||
print("error, number can't be smaller than min."); | ||
print("Wanna go again? y for yes and anykey for no. ") | ||
i = input(""); | ||
if i != "y": | ||
break; | ||
print(breaking * 10); | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
|
||
print("now type in the number") | ||
c = int(input(" ")) | ||
tries = 1; | ||
if(a > b): | ||
print("error, min can't be more than max. ") | ||
a = int(input("Min: ")) | ||
b = int(input("Max: ")) | ||
print("now type in the number") | ||
c = int(input(" ")) | ||
else: | ||
d = random.randint(a, b) | ||
elif d < c: | ||
a = d + 1; | ||
d = random.randint(a, b) | ||
print(f"guess {tries} :{str(d)}"); | ||
tries += 1; | ||
|
||
elif(d > c): | ||
b = d - 1; | ||
d = random.randint(a, b) | ||
print( "guess " + str(tries) + " :" + str(d)) | ||
tries += 1 | ||
elif d > c: | ||
b = d - 1; | ||
d = random.randint(a, b) | ||
print(f"guess {tries} :{str(d)}") | ||
tries += 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.
Lines 9-124
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
print("X = " + str(X)) | ||
print(f"X = {str(X)}") |
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
#rows and columns | ||
row = 1 | ||
column = 1 | ||
|
||
#for each line in the file | ||
for line in file: | ||
for row, line in enumerate(file, start=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.
Lines 26-46
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
This removes the following comments ( why? ):
#rows and columns
signature = base64.b64encode(digest).decode("utf-8") | ||
return signature | ||
return base64.b64encode(digest).decode("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.
Function sign
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
self.result = round(self.result, 2) | ||
self.label_2.setText(str(self.result)) | ||
else: | ||
self.result = int(self.new_label) * self.api(self.cur1, self.cur2) | ||
self.result = round(self.result, 2) | ||
self.label_2.setText(str(self.result)) | ||
self.result = round(self.result, 2) | ||
self.label_2.setText(str(self.result)) |
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 MainWindow.convert_fun
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
temp_in_celcius = json_data['main']['temp'] | ||
return temp_in_celcius | ||
return json_data['main']['temp'] |
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 get_temperature
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
weather_type = json_data['weather'][0]['description'] | ||
return weather_type | ||
return json_data['weather'][0]['description'] |
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 get_weather_type
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
wind_speed = json_data['wind']['speed'] | ||
return wind_speed | ||
return json_data['wind']['speed'] |
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 get_wind_speed
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
name = name.replace(char, "\\" + char) | ||
name = name.replace(char, f"\\{char}") |
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 escape_illegal
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
name = name + '.pdf' | ||
name = f'{name}.pdf' |
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
row_data = [] | ||
for cell in row: | ||
row_data.append(cell.value) | ||
row_data = [cell.value for cell in row] |
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 reader
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
currentlist = [] | ||
for current_col in range(start_col,numberofcols): | ||
currentlist.append(inputsheet.cell(current_row,current_col).value) | ||
currentlist = [ | ||
inputsheet.cell(current_row, current_col).value | ||
for current_col in range(start_col, numberofcols) | ||
] |
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 ExcelToList.convert
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
print("You selected:\n", "\n".join(filename for filename in filenames)) | ||
print("You selected:\n", "\n".join(filenames)) |
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:
- Simplify generator expression (
simplify-generator
)
|
||
#The Path of the directory to be sorted | ||
path = 'C:\\Users\\<USERNAME>\\Downloads' | ||
#This populates a list with the filenames in the directory | ||
list_ = os.listdir(path) | ||
|
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 3-24
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
#If the directory does not exist, it creates a new directory
#If a directory with the name 'ext' exists, it moves the file to that directory
print(f'\nSEARCH RESULT: %d Files. %d Directory.' % (file_cnt, dir_cnt)) | ||
print('\\nSEARCH RESULT: %d Files. %d Directory.' % (file_cnt, dir_cnt)) |
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 88-88
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
for i in range(0, 3): | ||
for i in range(3): |
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 check_phone_number
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Replace range(0, x) with range(x) (
remove-zero-from-range
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
print('Phone number has been found! : ' + split) No newline at end of file | ||
print(f'Phone number has been found! : {split}') |
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 24-24
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
command1 = 'ren ' + fname + ' "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"' | ||
command1 = ( | ||
f'ren {fname}' + ' "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"') | ||
command2 = 'attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"' | ||
|
||
dct = read_json() | ||
|
||
if not fname in dct.keys(): | ||
if fname not in dct.keys(): |
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 lock
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify logical expression using De Morgan identities (
de-morgan
)
Folder Locker & Hider/locker.py
Outdated
status = 'unlocked' | ||
return 'unlocked' | ||
else: | ||
status = 'failed' | ||
|
||
return status No newline at end of file | ||
return 'failed' |
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 unlock
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
@@ -24,7 +24,6 @@ def folder_manager(path,exception_file,extensions): | |||
if type( extensions) is not list: | |||
raise Exception('Expected a list object.') | |||
extensions = set( extensions) | |||
|
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 folder_manager
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Merge nested if conditions (
merge-nested-ifs
) - Remove redundant continue statement (
remove-redundant-continue
)
url = self.base_url + "users/" + args[0] | ||
url = f'{self.base_url}users/{args[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 GithubBot.get_user_details
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
url = self.base_url + "repos/" + args[0] + "/" + args[1] | ||
url = f'{self.base_url}repos/{args[0]}/{args[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 GithubBot.get_repo_details
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
current_row = [] | ||
all_th = tr.findAll('th') | ||
all_td = tr.findAll('td') | ||
for th in all_th: | ||
current_row.append(th.text) | ||
for td in all_td: | ||
current_row.append(td.text) | ||
current_row = [th.text for th in all_th] | ||
current_row.extend(td.text for td in all_td) |
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 HTMLTableToList.get_list
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
) - Replace a for append loop with list extend (
for-append-to-extend
)
return ''.join(found_numbers[0:4]) | ||
return ''.join(found_numbers[:4]) |
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 parse_film_year
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
if value == 'Q' or value == 'q': | ||
if value in ['Q', 'q']: | ||
user_selected(value) | ||
elif value == 'C' or value == 'c': | ||
elif value in ['C', 'c']: | ||
if (callback.__name__ == 'process_px_to_rem'): | ||
process_rem_to_px() | ||
return | ||
else: | ||
process_px_to_rem() | ||
return | ||
return |
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 process_check
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
if user_input == 'A' or user_input == 'a': # PX to REM | ||
if user_input in ['A', 'a']: # PX to REM | ||
process_px_to_rem() | ||
elif user_input == 'B' or user_input == 'b': # REM to PX | ||
elif user_input in ['B', 'b']: # REM to PX | ||
process_rem_to_px() | ||
elif user_input == 'Q' or user_input == 'q': | ||
elif user_input in ['Q', 'q']: |
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 user_selected
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
if unit == "atm": | ||
bar = float(atm) * 1.01325 | ||
return bar | ||
else: | ||
return "Invalid unit" | ||
return float(atm) * 1.01325 if unit == "atm" else "Invalid unit" |
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 atmospeheres_to_bars
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if unit == "bar": | ||
atm = float(bar) / 1.01325 | ||
return atm | ||
else: | ||
return "Invalid unit" | ||
return float(bar) / 1.01325 if unit == "bar" else "Invalid unit" |
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 bars_to_atmospheres
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if unit == "atm": | ||
mm_hg = float(atm) * 760 | ||
return mm_hg | ||
else: | ||
return "Invalid unit" | ||
return float(atm) * 760 if unit == "atm" else "Invalid unit" |
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 atmospheres_to_milimeter_mercury
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.19%.
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!