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(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)
| 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)
| missed = 0 | ||
| while len(word) > 0: | ||
| main = "" | ||
| missed = 0 | ||
| for letter in word: | ||
| if letter in guessmade: | ||
| main = main + letter | ||
| else: | ||
| main = main + "_" + " " | ||
| main = main + letter if letter in guessmade else f"{main}_ " |
There was a problem hiding this comment.
Function hangman refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop) - Replace if statement with if expression (
assign-if-exp) - Simplify conditional into switch-like form [×4] (
switch) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| player.y += player_speed | ||
| if player.top <= 0: | ||
| player.top = 0 | ||
| player.top = max(player.top, 0) |
There was a problem hiding this comment.
Function player_movement refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| if opponent.top <= 0: | ||
| opponent.top = 0 | ||
| opponent.top = max(opponent.top, 0) |
There was a problem hiding this comment.
Function opponent_ai refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| for i in range(4): | ||
| for _ in range(4): | ||
| n = input("Enter noun : ") | ||
| noun.append(n) | ||
| plural = [] | ||
| for i in range(6): | ||
| for _ in range(6): | ||
| pn = input("Enter plural noun : ") | ||
| plural.append(pn) | ||
| adjective = [] | ||
| for i in range(2): | ||
| for _ in range(2): |
There was a problem hiding this comment.
Lines 4-23 refactored with the following changes:
- Replace unused for index with underscore [×3] (
for-index-underscore) - Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation)
| 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)
| self.run_query(query, parameters) | ||
| self.edit_wind.destroy() | ||
| self.message['text'] = 'Record {} updated successfylly'.format(name) | ||
| self.message['text'] = f'Record {name} updated successfylly' |
There was a problem hiding this comment.
Function Product.edit_records refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
|
|
||
| # If there is no data, we add the value in the top element and return | ||
| if self.top == None: | ||
| if self.top is None: |
There was a problem hiding this comment.
Function Stack.push refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| def pop(self): | ||
| # If there is no data in the top node, we return | ||
| if self.top == None: | ||
| if self.top is None: |
There was a problem hiding this comment.
Function Stack.pop refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| while i < (num + 1) : | ||
| while i < k + 1: | ||
| print(" " * k, end = "") | ||
| j = 0 | ||
|
|
||
| while j <= t: | ||
| print("*", "", end="") | ||
| j = j + 1 | ||
| i = i + 1 | ||
| j += 1 | ||
|
|
||
| i += 1 | ||
| t = t + 1 | ||
| k = k - 1 | ||
| k -= 1 | ||
|
|
There was a problem hiding this comment.
Lines 11-22 refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable) - Replace assignment with augmented assignment [×3] (
aug-assign)
| def generate_board(num): | ||
| base = 3 | ||
| side = base * base | ||
| side = base**2 |
There was a problem hiding this comment.
Function generate_board refactored with the following changes:
- Replace x * x with x ** 2 [×2] (
square-identity) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# default number of empty slots
# given number of empty slots
| print(str(bo[i][j]) + " ", end="") | ||
| print(f"{str(bo[i][j])} ", end="") |
There was a problem hiding this comment.
Function print_board refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| # searching for next empty solt | ||
| slot = next_empty(bo) | ||
| if not slot: | ||
| if slot := next_empty(bo): | ||
| row, col = slot | ||
| else: | ||
| # return True if there is no empty slot | ||
| return True | ||
| else: | ||
| row, col = slot |
There was a problem hiding this comment.
Function solve refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Swap if/else branches (
swap-if-else-branches)
This removes the following comments ( why? ):
# searching for next empty solt
| return | ||
|
|
||
| else: | ||
| if action == 'inspect': | ||
| print("\n" + ZONE_MAP[player.location]["DESCRIPTION"]) | ||
| return | ||
|
|
||
| elif action == 'examine' or action == 'interact': | ||
| print("\n" + ZONE_MAP[player.location]["EXAMINATION"]) | ||
| return | ||
|
|
||
| elif action == 'look': | ||
| elif action == 'inspect': | ||
| print("\n" + ZONE_MAP[player.location]["DESCRIPTION"]) | ||
| elif action in ['examine', 'interact']: | ||
| print("\n" + ZONE_MAP[player.location]["EXAMINATION"]) | ||
| elif action == 'look': | ||
| # Display effects if there are any. | ||
| if len(player.effects) > 0: | ||
| print("\nYou have entitled with the following effects:") | ||
| for effect in player.effects: | ||
| sys.stdout.write("\t" + effect + "\n") | ||
| sys.stdout.flush() | ||
| time.sleep(0.5) | ||
|
|
||
| return | ||
| if len(player.effects) > 0: | ||
| print("\nYou have entitled with the following effects:") | ||
| for effect in player.effects: | ||
| sys.stdout.write("\t" + effect + "\n") | ||
| sys.stdout.flush() | ||
| time.sleep(0.5) | ||
|
|
||
| else: | ||
| print("\nYou have no effects.\n") | ||
| return | ||
| else: | ||
| print("\nYou have no effects.\n") | ||
| else: | ||
| print("\nI don't understand that command.\nPlease enter a valid command. ⚠️\n") | ||
|
|
||
| else: | ||
| print("\nI don't understand that command.\nPlease enter a valid command. ⚠️\n") | ||
| return | ||
| return |
There was a problem hiding this comment.
Function player_interact refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Hoist repeated code outside conditional statement [×3] (
hoist-statement-from-if) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| else : | ||
| else: | ||
| if TieGame(): | ||
| print("Tie Game") | ||
| x = input("Do you want to play again? (y/n)") | ||
| if x.lower() == 'y' or x.lower() =='yes': | ||
| if x.lower() in ['y', 'yes']: | ||
| StartTheGame() | ||
|
|
There was a problem hiding this comment.
Lines 173-179 refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
|
|
||
| possible_words = [] | ||
|
|
There was a problem hiding this comment.
Function find_possible_words refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| for i in range(6): | ||
|
|
||
| return(possible_words) | ||
| for _ in range(6): |
There was a problem hiding this comment.
Lines 52-69 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Merge append into list declaration [×5] (
merge-list-append)
| else: | ||
| score += 3 | ||
|
|
||
| score += random.randint(5,10) if answer == "2" else 3 |
There was a problem hiding this comment.
Lines 42-204 refactored with the following changes:
- Replace if statement with if expression [×10] (
assign-if-exp) - Replace call to format with f-string (
use-fstring-for-formatting)
| ret += " " | ||
| else: | ||
| ret += tmp + " " | ||
| ret += f"{tmp} " |
There was a problem hiding this comment.
Function parse_infix refactored with the following changes:
- Use f-string instead of string concatenation (
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!