Conversation
| if node.left is not None: | ||
| self._add(data, node.left) | ||
| else: | ||
| if node.left is None: | ||
| node.left = Node(data) | ||
| else: | ||
| if node.right is not None: | ||
| self._add(data, node.right) | ||
| else: | ||
| node.right = Node(data) | ||
| self._add(data, node.left) | ||
| elif node.right is not None: | ||
| self._add(data, node.right) | ||
| else: | ||
| node.right = Node(data) |
There was a problem hiding this comment.
Function Tree._add refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Swap if/else branches (
swap-if-else-branches)
| if self.root is not None: | ||
| return self._find(data, self.root) | ||
| else: | ||
| return None | ||
| return self._find(data, self.root) if self.root is not None else None |
There was a problem hiding this comment.
Function Tree.find refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| print(str(node.data) + ' ') | ||
| print(f'{str(node.data)} ') |
There was a problem hiding this comment.
Function Tree._printTree refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| output = "" | ||
| output = "" | ||
| string = string.lower() | ||
| string = string.strip() | ||
| if string == "": | ||
| if not (string := string.strip()): | ||
| return(self.blank_string) | ||
| else: | ||
| for c in string: | ||
| for k,v in self.key.items(): | ||
| if v == c: | ||
| output += k | ||
|
|
||
| for c in string: | ||
| for k,v in self.key.items(): | ||
| if v == c: | ||
| output += k | ||
|
|
There was a problem hiding this comment.
Function main.decrypt_string refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Swap if/else branches [×2] (
swap-if-else-branches) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| (x,y) = caterpillar.pos() | ||
| outside = x < left_wall or x > right_Wall or y > top_wall or y < bottom_wall | ||
| return outside | ||
| return x < left_wall or x > right_Wall or y > top_wall or y < bottom_wall |
There was a problem hiding this comment.
Function outside_window refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| c.itemconfigure(lives_text , text='Lives : ' + str(lives_remaning)) | ||
| c.itemconfigure(lives_text, text=f'Lives : {lives_remaning}') |
There was a problem hiding this comment.
Function lose_a_life 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)
| c.itemconfigure(score_text , text='Score : ' + str(score)) | ||
| c.itemconfigure(score_text, text=f'Score : {str(score)}') |
There was a problem hiding this comment.
Function increase_score refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| if(re.fullmatch(regex, email)): | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
| return bool((re.fullmatch(regex, email))) |
There was a problem hiding this comment.
Function isValidEmail refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| username = email[0:email.index('@')] | ||
| username = email[:email.index('@')] |
There was a problem hiding this comment.
Lines 16-16 refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', | ||
| 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', | ||
| 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', | ||
| 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', | ||
| 'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----', | ||
| '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', | ||
| '6': '-....', '7': '--...', '8': '---..', '9': '----.', | ||
| '&': '.-...', "'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.', | ||
| ':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-', | ||
| '-': '-....-', '+': '.-.-.', '"': '.-..-.', '?': '..--..', '/': '-..-.' | ||
| 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', | ||
| 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', | ||
| 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', | ||
| 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', | ||
| 'Y': '-.--', 'Z': '--..', ' ': ' ', '0': '-----', | ||
| '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', | ||
| '6': '-....', '7': '--...', '8': '---..', '9': '----.', | ||
| '&': '.-...', "'": '.----.', '@': '.--.-.', ')': '-.--.-', '(': '-.--.', | ||
| ':': '---...', ',': '--..--', '=': '-...-', '!': '-.-.--', '.': '.-.-.-', | ||
| '-': '-....-', '+': '.-.-.', '"': '.-..-.', '?': '..--..', '/': '-..-.' | ||
| } | ||
| string="" | ||
| for x in message: | ||
| string+=char_to_dots[x.upper()]+' ' | ||
| return string[0:-1] | ||
| string = "".join(f'{char_to_dots[x.upper()]} ' for x in message) | ||
| return string[:-1] |
There was a problem hiding this comment.
Function encode_morse refactored with the following changes:
- Use str.join() instead of for loop (
use-join) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| print(str(err)) | ||
| print(err) | ||
| return out, return_code | ||
| except Exception as err: | ||
| print("Exception Occurred while executing module : %s", str(err)) | ||
| print("Exception Occurred while executing module : %s", err) |
There was a problem hiding this comment.
Function execute_shell_command refactored with the following changes:
- Remove unnecessary call to
str()withinprint()[×2] (remove-str-from-print)
| cv2.data.haarcascades + "haarcascade_frontalface_default.xml") | ||
| f"{cv2.data.haarcascades}haarcascade_frontalface_default.xml" | ||
| ) | ||
| body_cascade = cv2.CascadeClassifier( | ||
| cv2.data.haarcascades + "haarcascade_fullbody.xml") | ||
| f"{cv2.data.haarcascades}haarcascade_fullbody.xml" | ||
| ) |
There was a problem hiding this comment.
Lines 6-8 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| blur = cv2.GaussianBlur(gray, (5, 5), 0) | ||
| canny = cv2.Canny(blur, 50, 150) | ||
| return canny | ||
| return cv2.Canny(blur, 50, 150) |
There was a problem hiding this comment.
Function canny refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| masked_image = cv2.bitwise_and(image, mask) | ||
| return masked_image | ||
| return cv2.bitwise_and(image, mask) |
There was a problem hiding this comment.
Function roi refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if 'user' in session: | ||
| return redirect("/") | ||
| return render_template("login.html") | ||
| return redirect("/") if 'user' in session else render_template("login.html") |
There was a problem hiding this comment.
Function login refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| imagesJPG = [] | ||
|
|
||
| for index, link in enumerate(imgSRC): | ||
| for link in imgSRC: |
There was a problem hiding this comment.
Function get_pdf refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| def lcm(a,b): | ||
| if a<0 or b<0: return | ||
| L = a if a > b else b | ||
| L = max(a, b) |
There was a problem hiding this comment.
Function lcm refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| def hcf(a,b): | ||
| if a<0 or b<0: return | ||
| H = a if a<b else b | ||
| H = min(a, b) |
There was a problem hiding this comment.
Function hcf refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| # Size and font of score label (Top-Left) | ||
| score_font = pygame.font.SysFont("arial", 15) | ||
| value = score_font.render(" Score: " + str(score), True, white) | ||
| value = score_font.render(f" Score: {str(score)}", True, white) |
There was a problem hiding this comment.
Function score refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| snake_Head = [] | ||
| snake_Head.append(x1) | ||
| snake_Head.append(y1) | ||
| snake_Head = [x1, y1] |
There was a problem hiding this comment.
Function gameLoop refactored with the following changes:
- Merge append into list declaration [×2] (
merge-list-append)
| content = wikipedia.summary(title, sentences = sentences) | ||
|
|
||
| return content | ||
| return wikipedia.summary(title, sentences = sentences) |
There was a problem hiding this comment.
Function page refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if specify_num_of_sentences == "y" or specify_num_of_sentences == "Y": | ||
| if specify_num_of_sentences in ["y", "Y"]: |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| o = int(x + columns * y) | ||
| o = int(x + columns * y) | ||
| N = int(8 * ((f * e - c * d * g) * m - c * d * e - f * g - l * d * n)) # luminance index | ||
| if rows > y and y > 0 and x > 0 and columns > x and D > z[o]: | ||
| z[o] = D | ||
| b[o] = chars[N if N > 0 else 0] | ||
| b[o] = chars[max(N, 0)] |
There was a problem hiding this comment.
Lines 76-97 refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity) - Swap if/else to remove empty if body (
remove-pass-body) - Hoist repeated code outside conditional statement [×2] (
hoist-statement-from-if) - Swap positions of nested conditionals [×2] (
swap-nested-ifs)
| parameters = (self.name.get(), self.price.get()) | ||
| self.run_query(query, parameters) | ||
| self.message['text'] = 'Product {} added Successfully'.format(self.name.get()) | ||
| self.message['text'] = f'Product {self.name.get()} added Successfully' |
There was a problem hiding this comment.
Function Product.add_product refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| query = 'DELETE FROM product WHERE name = ?' | ||
| self.run_query(query, (name, )) | ||
| self.message['text'] = 'Record {} deleted Successfully'.format(name) | ||
| self.message['text'] = f'Record {name} deleted Successfully' |
There was a problem hiding this comment.
Function Product.delete_product refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| count = 0 | ||
|
|
||
| for obj in ZONE_MAP: | ||
| if obj["SOLVED"]: count += 1 | ||
|
|
||
| count = sum(1 for obj in ZONE_MAP if obj["SOLVED"]) |
There was a problem hiding this comment.
Function ifSolved refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension)
|
|
There was a problem hiding this comment.
Function setup_game refactored with the following changes:
- Simplify conditional into switch-like form [×5] (
switch) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation)
| print("Let's Start") | ||
| print("Let's Start") | ||
| typing_speed() | ||
|
|
||
| while True : | ||
| if input("Do you want to try again? (y/n): ")=="y": | ||
| print("\n") | ||
| typing_speed() | ||
| else: | ||
| break No newline at end of file | ||
| while True: | ||
| if input("Do you want to try again? (y/n): ") != "y": | ||
| break | ||
| print("\n") | ||
| typing_speed() No newline at end of file |
There was a problem hiding this comment.
Lines 39-47 refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| #initialize | ||
| board = [' ' for x in range(10)] | ||
| #initialize | ||
| board = [' ' for _ in range(10)] |
There was a problem hiding this comment.
Lines 5-6 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3]) | ||
| print(f' {board[1]} | {board[2]} | {board[3]}') | ||
| print('-----------') | ||
| print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6]) | ||
| print(f' {board[4]} | {board[5]} | {board[6]}') | ||
| print('-----------') | ||
| print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9]) | ||
| print(f' {board[7]} | {board[8]} | {board[9]}') |
There was a problem hiding this comment.
Function printBoard refactored with the following changes:
- Use f-string instead of string concatenation [×15] (
use-fstring-for-concatenation)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!