Skip to content

Commit

Permalink
Change tuple type hint to Tuple[int, int, int] to satisfy mypy. Retur…
Browse files Browse the repository at this point in the history
…n tuple naively instead of type casting from list to tuple. Add 2 regression tests for robustness.
  • Loading branch information
evanjhoward11 committed May 8, 2024
1 parent 6ed49a9 commit 011904b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stockfish/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def is_move_correct(self, move_value: str) -> bool:

def get_wdl_stats(
self, get_as_tuple: bool = False
) -> Union[list[int] | tuple[int, ...] | None]:
) -> Union[list[int] | tuple[int, int, int] | None]:
"""Returns Stockfish's win/draw/loss stats for the side to move.
Args:
Expand Down Expand Up @@ -741,7 +741,7 @@ def get_wdl_stats(
wdl_stats = [int(split_line[i]) for i in range(wdl_index + 1, wdl_index + 4)]

if get_as_tuple:
return tuple(wdl_stats)
return (wdl_stats[0], wdl_stats[1], wdl_stats[2])
return wdl_stats

def does_current_engine_version_have_wdl_option(self) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions tests/stockfish/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ def test_get_wdl_stats(self, stockfish: Stockfish):

wdl_stats_4 = stockfish.get_wdl_stats(get_as_tuple=True)
assert isinstance(wdl_stats_4, tuple) and len(wdl_stats_4) == 3
assert wdl_stats_3 == list(wdl_stats_4)
assert tuple(wdl_stats_3) == wdl_stats_4

stockfish.set_fen_position("8/8/8/8/8/3k4/3p4/3K4 w - - 0 1")
assert stockfish.get_wdl_stats() is None
Expand Down

0 comments on commit 011904b

Please sign in to comment.