Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jan 12, 2022

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:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from Jerry-py January 12, 2022 01:33
Comment on lines -12 to +21
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__}')
Copy link
Author

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:

Comment on lines -45 to +49
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)
}

Copy link
Author

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:

Comment on lines -59 to +61
if y != "🌊" or y != "🔥":
return False
return False
Copy link
Author

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:

for y, column in enumerate(row):
for column in row:
Copy link
Author

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:

Comment on lines -83 to +93
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,
)

Copy link
Author

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)

Comment on lines -173 to +179
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)
Copy link
Author

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:

Comment on lines -24 to +25
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
Copy link
Author

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:

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]
Copy link
Author

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:

Comment on lines -36 to +39
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)
])
Copy link
Author

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:

scn_lst = []
for thing in i:
scn_lst.append(dct[thing])
scn_lst = [dct[thing] for thing in i]
Copy link
Author

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:

Comment on lines -43 to +41
if num3 > 7:
num3 = 7
num3 = min(num3, 7)
Copy link
Author

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:

Comment on lines -74 to +71
if thing == "p" or thing == "tp":
if thing in ["p", "tp"]:
Copy link
Author

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:

Comment on lines -81 to +78
if y == "t" or y == "tp":
if y in ["t", "tp"]:
Copy link
Author

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:

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))
Copy link
Author

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)

Comment on lines -185 to +193
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,
)

Copy link
Author

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:

Comment on lines -20 to +19
for x in range(0, 4):
for y in range(0, 4):
for x in range(4):
for y in range(4):
Copy link
Author

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:

Comment on lines -45 to +41
for x in range(0, 4):
for x in range(4):
Copy link
Author

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:

Comment on lines -70 to +64
for y in range(0, 4):
for y in range(4):
Copy link
Author

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:

Comment on lines -95 to +88
for y in range(0, 4):
for x in range(0, 4):
for y in range(4):
for x in range(4):
Copy link
Author

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:

Comment on lines -125 to +115
if pickanumber < 1:
num = 4
else:
num = 2

num = 4 if pickanumber < 1 else 2
Copy link
Author

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:

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:
Copy link
Author

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:

Comment on lines -15 to +16
lst = []
g = [f"{self.seperator}{i}" for i in range(self.x + 1)]
lst.append(g)
lst = [g]
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jan 12, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.17%.

Quality metrics Before After Change
Complexity 62.25 ⛔ 61.73 ⛔ -0.52 👍
Method Length 139.31 😞 138.37 😞 -0.94 👍
Working memory 15.77 ⛔ 15.79 ⛔ 0.02 👎
Quality 31.57% 😞 31.74% 😞 0.17% 👍
Other metrics Before After Change
Lines 2820 2790 -30
Changed files Quality Before Quality After Quality Change
disgames/main.py 90.29% ⭐ 90.88% ⭐ 0.59% 👍
disgames/mixins/battleship.py 14.39% ⛔ 13.50% ⛔ -0.89% 👎
disgames/mixins/checkers.py 17.42% ⛔ 17.88% ⛔ 0.46% 👍
disgames/mixins/chess.py 27.78% 😞 28.51% 😞 0.73% 👍
disgames/mixins/connect4.py 22.24% ⛔ 21.99% ⛔ -0.25% 👎
disgames/mixins/madlib.py 77.71% ⭐ 77.78% ⭐ 0.07% 👍
disgames/mixins/minesweeper.py 50.32% 🙂 50.67% 🙂 0.35% 👍
disgames/mixins/snake.py 62.33% 🙂 62.13% 🙂 -0.20% 👎
disgames/mixins/snl.py 18.40% ⛔ 18.55% ⛔ 0.15% 👍
disgames/mixins/soko.py 16.37% ⛔ 15.92% ⛔ -0.45% 👎
disgames/mixins/sudoko.py 26.29% 😞 28.36% 😞 2.07% 👍
disgames/mixins/ttt.py 39.26% 😞 40.35% 😞 1.09% 👍
disgames/mixins/ttt_reactions.py 32.84% 😞 33.52% 😞 0.68% 👍
disgames/mixins/two048.py 47.36% 😞 46.86% 😞 -0.50% 👎
disgames/utils/board.py 68.04% 🙂 68.82% 🙂 0.78% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
disgames/mixins/connect4.py Connect4.connect4 97 ⛔ 743 ⛔ 25 ⛔ 2.16% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
disgames/mixins/battleship.py Battleships.battleship 74 ⛔ 1484 ⛔ 27 ⛔ 2.18% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
disgames/mixins/checkers.py Checkers.checkers 101 ⛔ 986 ⛔ 22 ⛔ 3.20% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
disgames/mixins/ttt_reactions.py TicTacToeReactions.tictactoe 54 ⛔ 735 ⛔ 31 ⛔ 3.31% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
disgames/mixins/soko.py Sokoban.sokoban 242 ⛔ 1651 ⛔ 21 ⛔ 3.54% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants