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

Satisfy mypy and black. #1

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Stockfish:
# Used in test_models: will count how many times the del function is called.

def __init__(
self, path: str = "stockfish", depth: int = 15, parameters: dict = None
self,
path: str = "stockfish",
depth: int = 15,
parameters: Optional[dict] = None,
) -> None:
self._DEFAULT_STOCKFISH_PARAMS = {
"Debug Log File": "",
Expand Down Expand Up @@ -324,7 +327,9 @@ def set_elo_rating(self, elo_rating: int = 1350) -> None:
{"UCI_LimitStrength": "true", "UCI_Elo": elo_rating}
)

def get_best_move(self, wtime: int = None, btime: int = None) -> Optional[str]:
def get_best_move(
self, wtime: Optional[int] = None, btime: Optional[int] = None
) -> Optional[str]:
"""Returns best move with current position on the board.
wtime and btime arguments influence the search only if provided.

Expand Down Expand Up @@ -622,8 +627,12 @@ def __gt__(self, other: Stockfish.TopMove) -> bool:
# both moves has no mate, compare the depth first than centipawn
if self.depth == other.depth:
if self.cp == other.cp:
if self.seldepth is None or other.seldepth is None:
raise RuntimeError("None value when it should be an int.")
return self.seldepth > other.seldepth
else:
if self.cp is None or other.cp is None:
raise RuntimeError("None value when it should be an int.")
return self.cp > other.cp
else:
return self.depth > other.depth
Expand Down Expand Up @@ -651,7 +660,9 @@ def __lt__(self, other: Stockfish.TopMove) -> bool:
return not self.__gt__(other)

# equal move, by "move", not by score/evaluation
def __eq__(self, other: Stockfish.TopMove) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Stockfish.TopMove):
return False
return self.move == other.move

def generate_top_moves(
Expand Down Expand Up @@ -738,8 +749,9 @@ def generate_top_moves(
top_moves.insert(0, move)
break
else:
raise ValueError(f"Stockfish returned the best move: {best_move}, but it's not in the list")

raise ValueError(
f"Stockfish returned the best move: {best_move}, but it's not in the list"
)

yield top_moves[:num_top_moves]

Expand Down