Conversation
| 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.
Function Game.game_over refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all)
| if(a > b): | ||
| (print("error, min can't be more than max. ")) | ||
| a = int(input("Min: ")) | ||
| b = int(input("Max: ")) | ||
| else: | ||
| break; | ||
| if a <= b: | ||
| break; | ||
| (print("error, min can't be more than max. ")) | ||
| a = int(input("Min: ")) | ||
| b = int(input("Max: ")) | ||
| breaking = "------------" | ||
| print("now type in the number: ") | ||
| c = int(input(" ")) | ||
| tries = 1; | ||
| d = random.randint(a, b) | ||
| while True: | ||
| if(d == c and tries == 1): | ||
| print("guess 1: " + str(d)) | ||
| print("HA, gotcha. I got it in 1 time!") | ||
| print("Wanna go again? y for yes and anykey for no. ") | ||
| i = input(""); | ||
| if(i == "y"): | ||
| print(breaking * 10); | ||
| a = int(input("Min: ")) | ||
| b = int(input("Max: ")) | ||
| if (d == c and tries == 1): | ||
| print(f"guess 1: {str(d)}") | ||
| print("HA, gotcha. I got it in 1 time!") | ||
| 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) | ||
|
|
||
| else: | ||
| break; | ||
| elif(d == c): | ||
| print("HA, gotcha. I got it in " + str(tries - 1) + " times!") | ||
| print("Wanna go again? y for yes and anykey for no. ") | ||
| i = input(""); | ||
| if(i == "y"): | ||
| 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) | ||
|
|
||
| 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(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"): | ||
| print(breaking * 10); | ||
| a = int(input("Min: ")) | ||
| b = int(input("Max: ")) | ||
| elif d == c: | ||
| print(f"HA, gotcha. I got it in {str(tries - 1)} times!") | ||
| print("Wanna go again? y for yes and anykey for no. ") | ||
| i = input(""); | ||
| if i != "y": | ||
| break; | ||
|
|
||
| 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) | ||
| 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.
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)
| def main(x): | ||
| X = solver(x) | ||
| print("X = " + str(X)) | ||
| print(f"X = {str(X)}") |
There was a problem hiding this comment.
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.
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
| digestmod=hashs.get(hash, hashlib.md5)).digest() | ||
| signature = base64.b64encode(digest).decode("utf-8") | ||
| return signature | ||
| return base64.b64encode(digest).decode("utf-8") |
There was a problem hiding this comment.
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.
Function MainWindow.convert_fun refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| def get_temperature(json_data): | ||
| temp_in_celcius = json_data['main']['temp'] | ||
| return temp_in_celcius | ||
| return json_data['main']['temp'] |
There was a problem hiding this comment.
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.
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.
Function get_wind_speed refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| illegal_char_array = ['\\', '&', '%', '$', '#', '_', '{', '}', '~', '^'] | ||
| for char in illegal_char_array: | ||
| name = name.replace(char, "\\" + char) | ||
| name = name.replace(char, f"\\{char}") |
There was a problem hiding this comment.
Function escape_illegal refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| if not name.endswith('.pdf'): | ||
| name = name + '.pdf' | ||
| name = f'{name}.pdf' |
There was a problem hiding this comment.
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.
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.
Function ExcelToList.convert refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| def main(): | ||
| filenames = select_files() | ||
| 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.
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.
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.
Lines 88-88 refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| if len(string) != 12: | ||
| return False | ||
| for i in range(0, 3): | ||
| for i in range(3): |
There was a problem hiding this comment.
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}') No newline at end of file |
There was a problem hiding this comment.
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.
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)
| status = 'unlocked' | ||
| return 'unlocked' | ||
| else: | ||
| status = 'failed' | ||
|
|
||
| return status No newline at end of file | ||
| return 'failed' No newline at end of file |
There was a problem hiding this comment.
Function unlock refactored with the following changes:
- Lift return into if (
lift-return-into-if)
| if type( extensions) is not list: | ||
| raise Exception('Expected a list object.') | ||
| extensions = set( extensions) | ||
|
|
There was a problem hiding this comment.
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)
|
|
||
| def get_user_details(self, args): | ||
| url = self.base_url + "users/" + args[0] | ||
| url = f'{self.base_url}users/{args[0]}' |
There was a problem hiding this comment.
Function GithubBot.get_user_details refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| def get_repo_details(self, args): | ||
| 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.
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.
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)
| def parse_film_year(year_text): | ||
| found_numbers = re.findall("[0-9]", year_text) | ||
| return ''.join(found_numbers[0:4]) | ||
| return ''.join(found_numbers[:4]) |
There was a problem hiding this comment.
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.
Function process_check refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| 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.
Function user_selected refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| return bar | ||
| else: | ||
| return "Invalid unit" | ||
| return float(atm) * 1.01325 if unit == "atm" else "Invalid unit" |
There was a problem hiding this comment.
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.
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.
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
masterrefactored 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
masterbranch, then run:Help us improve this pull request!