Conversation
| entries = [] | ||
| entries = [ | ||
| '- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format( | ||
| sys.version_info | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info)) | ||
| version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=1) | ||
| entries.append('- Disgames v{0.major}.{0.minor}.{0.micro}'.format(version_info)) | ||
| entries.append(f'- aiohttp v{aiohttp.__version__}') | ||
| entries.append(f'- aiohttp v{aiohttp.__version__}') |
There was a problem hiding this comment.
Function version refactored with the following changes:
- Merge append into list declaration (
merge-list-append)
| dct = {} | ||
| for i in range(1, 10): | ||
| dct[i] = f"{i}\N{variation selector-16}\N{combining enclosing keycap}" | ||
| dct = { | ||
| i: f"{i}\N{variation selector-16}\N{combining enclosing keycap}" | ||
| for i in range(1, 10) | ||
| } | ||
|
|
There was a problem hiding this comment.
Function Battleships.format_battleships_board refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension)
| if y != "🌊" or y != "🔥": | ||
| return False | ||
| return False |
There was a problem hiding this comment.
Function Battleships.has_won_battleship refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| for x, row in enumerate(board): | ||
| scn_lst = [dct[str(x + 1)]] | ||
| for y, column in enumerate(row): | ||
| for column in row: |
There was a problem hiding this comment.
Function Checkers.format_checkers_board refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| f"Invalid syntax: Correct directions ul (up left), dl (down left), ur (up right), dr (down right)", | ||
| 'Invalid syntax: Correct directions ul (up left), dl (down left), ur (up right), dr (down right)', | ||
| delete_after=5, | ||
| ) | ||
|
|
||
| continue | ||
| elif not len(coors) == 2: | ||
| elif len(coors) != 2: | ||
| await ctx.send( | ||
| f"Invalid syntax: The coordinates entered are invalid", | ||
| 'Invalid syntax: The coordinates entered are invalid', | ||
| delete_after=5, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function Checkers.checkers refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Simplify logical expression using De Morgan identities (
de-morgan) - Simplify conditional into switch-like form (
switch)
| else: | ||
| if visible_board[x][y] not in [" ","f"]: | ||
| await ctx.send( | ||
| f"Invalid Syntax: {coors} is already revealed", | ||
| delete_after=5, | ||
| ) | ||
| continue | ||
| visible_board[x][y] = str(grid[x][y]) | ||
| if visible_board[x][y] == "0": | ||
| visible_board = self.reveal_zeros(visible_board, grid, x, y) | ||
| if visible_board[x][y] not in [" ","f"]: | ||
| await ctx.send( | ||
| f"Invalid Syntax: {coors} is already revealed", | ||
| delete_after=5, | ||
| ) | ||
| continue | ||
| visible_board[x][y] = str(grid[x][y]) | ||
| if visible_board[x][y] == "0": | ||
| visible_board = self.reveal_zeros(visible_board, grid, x, y) |
There was a problem hiding this comment.
Function Minesweeper.minesweeper refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if self.length > 1 and (pt[0] * -1, pt[1] * -1) == self.direction: | ||
| pass | ||
| else: | ||
| self.direction = pt | ||
| if self.length <= 1 or (pt[0] * -1, pt[1] * -1) != self.direction: | ||
| self.direction = pt |
There was a problem hiding this comment.
Function SnakeGame.point refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body)
| lst = [] | ||
| for row in board: | ||
| lst.append(''.join([dct[column] for column in row])) | ||
| lst = [''.join([dct[column] for column in row]) for row in board] |
There was a problem hiding this comment.
Function SNL.format_snl_board refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| indexes = {} | ||
| for player in players: | ||
| indexes[player] = [9,0] | ||
| indexes = {player: [9,0] for player in players} | ||
| board = self.create_board() | ||
| player_string = f' '.join([f"{player.mention}: {tokens['p'+str(num)]}" for num, player in enumerate(players, start=1)]) | ||
| player_string = ' '.join([ | ||
| f"{player.mention}: {tokens['p'+str(num)]}" | ||
| for num, player in enumerate(players, start=1) | ||
| ]) |
There was a problem hiding this comment.
Function SNL.snl refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension) - Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Swap if/else to remove empty if body (
remove-pass-body)
| scn_lst = [] | ||
| for thing in i: | ||
| scn_lst.append(dct[thing]) | ||
| scn_lst = [dct[thing] for thing in i] |
There was a problem hiding this comment.
Function Sokoban.format_soko_board refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| if num3 > 7: | ||
| num3 = 7 | ||
| num3 = min(num3, 7) |
There was a problem hiding this comment.
Function Sokoban.create_soko_board refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| if thing == "p" or thing == "tp": | ||
| if thing in ["p", "tp"]: |
There was a problem hiding this comment.
Function Sokoban.get_player refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if y == "t" or y == "tp": | ||
| if y in ["t", "tp"]: |
There was a problem hiding this comment.
Function Sokoban.has_won_soko refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if num in board[i][y]: | ||
| h = True | ||
| break | ||
| h = any(num in board[i][y] for i in range(9)) |
There was a problem hiding this comment.
Function Sudoko.create_sudoko_board refactored with the following changes:
- Use any() instead of for loop (
use-any)
| f"Invalid syntax: There is a another {str(num)} on the same row", | ||
| f'Invalid syntax: There is a another {num} on the same row', | ||
| delete_after=5, | ||
| ) | ||
|
|
||
| continue | ||
| else: | ||
| h = False | ||
| for i in range(9): | ||
| if str(num) in board[i][y]: | ||
| h = True | ||
| break | ||
| h = any(str(num) in board[i][y] for i in range(9)) | ||
| if h: | ||
| await ctx.send( | ||
| f"Invalid syntax: There is a another {str(num)} on the same column", | ||
| f'Invalid syntax: There is a another {num} on the same column', | ||
| delete_after=5, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function Sudoko.sudoko refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting) - Use any() instead of for loop (
use-any)
| for x in range(0, 4): | ||
| for y in range(0, 4): | ||
| for x in range(4): | ||
| for y in range(4): |
There was a problem hiding this comment.
Function _2048.go_up refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| for x in range(0, 4): | ||
| for x in range(4): |
There was a problem hiding this comment.
Function _2048.go_down refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| for y in range(0, 4): | ||
| for y in range(4): |
There was a problem hiding this comment.
Function _2048.go_right refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| for y in range(0, 4): | ||
| for x in range(0, 4): | ||
| for y in range(4): | ||
| for x in range(4): |
There was a problem hiding this comment.
Function _2048.go_left refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
| if pickanumber < 1: | ||
| num = 4 | ||
| else: | ||
| num = 2 | ||
|
|
||
| num = 4 if pickanumber < 1 else 2 |
There was a problem hiding this comment.
Function _2048.add_number refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| break | ||
|
|
||
| if zeroes == 0 and playsleft == False: | ||
| if zeroes == 0 and not playsleft: |
There was a problem hiding this comment.
Function _2048.get_result refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range) - Simplify comparison to boolean (
simplify-boolean-comparison)
| lst = [] | ||
| g = [f"{self.seperator}{i}" for i in range(self.x + 1)] | ||
| lst.append(g) | ||
| lst = [g] |
There was a problem hiding this comment.
Function Board.__str__ refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration (
merge-list-append)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.17%.
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
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!