-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Battleships.has_won_battleship
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
for y, column in enumerate(row): | ||
for column in row: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Checkers.format_checkers_board
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Sokoban.get_player
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
if y == "t" or y == "tp": | ||
if y in ["t", "tp"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Sokoban.has_won_soko
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
h = False | ||
for i in range(9): | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _2048.add_number
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
for y in range(0, 4): | ||
for y in range(4): | ||
zeroes += board[y].count(0) | ||
if zeroes > 0: | ||
break | ||
for x in range(0, 4): | ||
for x in range(4): | ||
if x < 3 and board[y][x + 1] == board[y][x]: | ||
playsleft = True | ||
break | ||
if y < 3 and board[y + 1][x] == board[y][x]: | ||
playsleft = True | ||
break | ||
if playsleft == True: | ||
if playsleft: | ||
break | ||
|
||
if zeroes == 0 and playsleft == False: | ||
if zeroes == 0 and not playsleft: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
main
refactored 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
main
branch, then run:Help us improve this pull request!