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)
| while True: | ||
| if(a > b): | ||
| (print("error, min can't be more than max. ")) | ||
| a = int(input("Min: ")) | ||
| b = int(input("Max: ")) | ||
| else: | ||
| break; | ||
| while a > b: | ||
| (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 {str(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 {str(tries)} :{str(d)}") | ||
| tries += 1 |
There was a problem hiding this comment.
Lines 8-124 refactored with the following changes:
- Removes or propagates redundant boolean expressions. (
remove-redundant-boolean) - Simplify logical expression using De Morgan identities (
de-morgan) - Move a guard clause in a while statement's body into its test. (
while-guard-to-condition) - 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)
| 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)
|
|
||
| def monitor(): | ||
| while (True): | ||
| while True: |
There was a problem hiding this comment.
Function monitor refactored with the following changes:
- 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)
| #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
| api_link = "https://min-api.cryptocompare.com/data/pricemulti?fsyms={}&tsyms={}".format(cur1, cur2) | ||
| api_link = f"https://min-api.cryptocompare.com/data/pricemulti?fsyms={cur1}&tsyms={cur2}" | ||
|
|
||
| resp = requests.get(api_link) | ||
| # print(r.status_code) | ||
| data = json.loads(resp.content) | ||
| # print(data) | ||
| var = data[self.cur1][self.cur2] | ||
| return var | ||
| return data[self.cur1][self.cur2] |
There was a problem hiding this comment.
Function MainWindow.api refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# print(data)
| 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)
| return ( | ||
| weather_details | ||
| + f"The weather in {city} is currently {weather_type} with a temperature of {temperature} degrees and wind speeds reaching {wind_speed} km/ph" | ||
| ) |
There was a problem hiding this comment.
Function get_weather_data refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| import requests | ||
| headers = {'accept': 'application/dns-json'} | ||
| url = "https://1.1.1.1/dns-query?name=%s&type=%s" % (record,type) | ||
| url = f"https://1.1.1.1/dns-query?name={record}&type={type}" |
There was a problem hiding this comment.
Function CloudFlareLookup refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
|
|
||
| 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)
| choice = input("Did you mean %s instead ? Enter Y for yes or N for no: " % get_close_matches(word, data.keys())[0]) | ||
| choice = input( | ||
| f"Did you mean {get_close_matches(word, data.keys())[0]} instead ? Enter Y for yes or N for no: " | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function show_def refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| 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)
| print("[>] Directory: %s" % dir_path) | ||
| print(f"[>] Directory: {dir_path}") | ||
| for files in os.listdir(dir_path): | ||
| if os.path.isfile(dir_path+files): | ||
| filelist.append(dir_path+files) | ||
| for _ in range(cnt): | ||
| print("\t", end=" ") | ||
| print("[+] File Name: %s" % files) | ||
| print(f"[+] File Name: {files}") | ||
| file_cnt+=1 | ||
| elif os.path.isdir(dir_path+files): | ||
| for i in range(cnt): | ||
| for _ in range(cnt): |
There was a problem hiding this comment.
Function fileSearch refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace unused for index with underscore (
for-index-underscore)
| carv = open('carv'+str(cnt)+'.jpeg', 'wb') | ||
| carv = open(f'carv{str(cnt)}.jpeg', 'wb') | ||
| for j in range(len(carv_cont)): | ||
| carv.write(carv_cont[j]) | ||
| print('[*] carv',str(cnt),'.jpeg is created!') | ||
| carv_list.append('carv'+str(cnt)+'.jpeg') | ||
| print('[*] carv', cnt, '.jpeg is created!') | ||
| carv_list.append(f'carv{str(cnt)}.jpeg') |
There was a problem hiding this comment.
Function Carving refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Remove unnecessary call to
str()withinprint()(remove-str-from-print)
| while(1): | ||
| while 1: | ||
| buf = file.read(0x200) | ||
| file.tell() | ||
| if(len(buf)==0): break | ||
| if(flag != 1): | ||
| if (flag != 1): | ||
| ishead = (str(buf[:3]).split('\'')[1]) | ||
| if (header == ishead) and (flag == 0): | ||
| contents.append(buf) | ||
| flag = 1 | ||
| elif (footer in (str(buf[-2:]).split('\'')[1])): | ||
| contents.append(buf) | ||
| return contents | ||
| else: | ||
| if(footer in (str(buf[-2:]).split('\'')[1])): | ||
| contents.append(buf) | ||
| return contents | ||
| else: | ||
| contents.append(buf) | ||
| contents.append(buf) |
There was a problem hiding this comment.
Function findSignature refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| 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)
| while(True): | ||
|
|
||
| while True: | ||
| choice = random.choice(list(state_capitals.keys())) | ||
| answer = input(('{}? '.format(choice))) | ||
| answer = input(f'{choice}? ') | ||
| if answer == state_capitals[choice]: | ||
| print("Correct! Nice job.") | ||
| elif answer.lower() == "exit": | ||
| print("Goodbye") | ||
| break | ||
| else: | ||
| print("Incorrect. The correct answer is {}".format(state_capitals[choice])) No newline at end of file | ||
| print(f"Incorrect. The correct answer is {state_capitals[choice]}") No newline at end of file |
There was a problem hiding this comment.
Lines 14-24 refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| 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)
| y = 0 | ||
| while y < height: | ||
| dat[y] = " "+dat[y]+" " | ||
| y += 1 | ||
| width = len(max(dat, key=len))+1 | ||
| counter = 0 | ||
| for y in range(height): | ||
| dat[y] = f" {dat[y]} " | ||
| x = 0 | ||
| line = "╔" | ||
| width = len(max(dat, key=len))+1 | ||
| while x < width-1: | ||
| line = line + "═" | ||
| line = f"{line}═" | ||
| x += 1 | ||
| line = line + "╗" | ||
| line = f"{line}╗" | ||
| print(line) | ||
| while counter < height: | ||
| for counter in range(height): | ||
| reqspaces = width -1- len(dat[counter]) | ||
| xsp = "" | ||
| while reqspaces > 0: | ||
| xsp = xsp + " " | ||
| xsp = f"{xsp} " | ||
| reqspaces -= 1 | ||
| print(borderstyle+dat[counter]+xsp+borderstyle) | ||
| counter += 1 | ||
| x = 0 | ||
| line = "╚" | ||
| while x < width-1: | ||
| line = line + "═" | ||
| line = f"{line}═" | ||
| x += 1 | ||
| line = line + "╝" | ||
| line = f"{line}╝" |
There was a problem hiding this comment.
Function drawboxtext refactored with the following changes:
- Replace while with for (
while-to-for) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Move assignment closer to its usage within a block (
move-assign-in-block)
| print('Input file is '+ str(args.inputfile)) | ||
| print('Output file is '+ str(args.outputfile)) | ||
| print('Image diameter will be '+ str(args.diameter)) | ||
| print(f'Input file is {str(args.inputfile)}') | ||
| print(f'Output file is {str(args.outputfile)}') | ||
| print(f'Image diameter will be {str(args.diameter)}') |
There was a problem hiding this comment.
Lines 15-17 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| save_path=asksaveasfile() | ||
|
|
||
| img.save(save_path+"_compressed.JPG") No newline at end of file | ||
| img.save(f"{save_path}_compressed.JPG") No newline at end of file |
There was a problem hiding this comment.
Lines 12-12 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| important = ImportanceChecker(query) | ||
|
|
||
| if (important): | ||
| if important := ImportanceChecker(query): |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| content = requests.get("https://www.instagram.com/"+username).content | ||
| content = requests.get(f"https://www.instagram.com/{username}").content | ||
| find=re.findall(r"logging_page_id.*show_suggested_profiles",str(content)) | ||
| user_id=((find[0][16:]).split(","))[0][14:-1] # We get the user id of the username | ||
| jsonreq=requests.get("https://i.instagram.com/api/v1/users/"+user_id+"/info/").content # using a link we get the whole info of the person | ||
| jsonreq = requests.get( | ||
| f"https://i.instagram.com/api/v1/users/{user_id}/info/").content |
There was a problem hiding this comment.
Lines 10-13 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
This removes the following comments ( why? ):
# using a link we get the whole info of the person
| fd_script_output = open(filename_script_output, 'w') # create file descriptor for script to write its stdout to | ||
| script_process = subprocess.Popen( # start new process running script | ||
| filename_script, | ||
| stdin=subprocess.PIPE, # needed for script_process.communicate() (see below) | ||
| stdout=fd_script_output # redirect output | ||
| ) | ||
| with open(filename_script_output, 'w') as fd_script_output: | ||
| script_process = subprocess.Popen( # start new process running script | ||
| filename_script, | ||
| stdin=subprocess.PIPE, # needed for script_process.communicate() (see below) | ||
| stdout=fd_script_output # redirect output | ||
| ) | ||
|
|
||
| while True: | ||
| with open(filename_own_input, 'r') as f: | ||
| if exit_keyword in f.read(): # check if we should exit | ||
| script_process.communicate(input=stop_command) # stop subprocess and wait for it to terminate | ||
| break | ||
| time.sleep(1) | ||
|
|
||
| fd_script_output.close() | ||
| while True: | ||
| with open(filename_own_input, 'r') as f: | ||
| if exit_keyword in f.read(): # check if we should exit | ||
| script_process.communicate(input=stop_command) # stop subprocess and wait for it to terminate | ||
| break | ||
| time.sleep(1) |
There was a problem hiding this comment.
Lines 15-29 refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
This removes the following comments ( why? ):
# create file descriptor for script to write its stdout to
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! |
|
SonarCloud Quality Gate failed.
|










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!