Skip to content

Commit

Permalink
Towards pyright compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Jul 31, 2024
1 parent 571658b commit f286d68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def from_chess960_pos(cls: Type[BaseBoardT], scharnagl: int) -> BaseBoardT:

class _BoardState:

def __init__(self, board: BoardT) -> None:
def __init__(self, board: Board) -> None:
self.pawns = board.pawns
self.knights = board.knights
self.bishops = board.bishops
Expand All @@ -1564,7 +1564,7 @@ def __init__(self, board: BoardT) -> None:
self.halfmove_clock = board.halfmove_clock
self.fullmove_number = board.fullmove_number

def restore(self, board: BoardT) -> None:
def restore(self, board: Board) -> None:
board.pawns = self.pawns
board.knights = self.knights
board.bishops = self.bishops
Expand Down
7 changes: 5 additions & 2 deletions chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ class Score(abc.ABC):
"""

@typing.overload
@abc.abstractmethod
def score(self, *, mate_score: int) -> int: ...
@typing.overload
@abc.abstractmethod
def score(self, *, mate_score: Optional[int] = None) -> Optional[int]: ...
@abc.abstractmethod
def score(self, *, mate_score: Optional[int] = None) -> Optional[int]:
Expand Down Expand Up @@ -2120,12 +2122,13 @@ def _new(self, board: chess.Board, game: object, options: ConfigMapping, opponen
if self.config.get("computer"):
self.send_line("computer")

self.send_line("force")
self.send_line("force")

if new_game:
fen = root.fen(shredder=board.chess960, en_passant="fen")
if variant != "normal" or fen != chess.STARTING_FEN or board.chess960:
self.send_line(f"setboard {fen}")
else:
self.send_line("force")

# Undo moves until common position.
common_stack_len = 0
Expand Down
8 changes: 4 additions & 4 deletions chess/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _transposition_key(self) -> Hashable:
else:
return super()._transposition_key()

def board_fen(self, promoted: Optional[bool] = None) -> str:
def board_fen(self, *, promoted: Optional[bool] = None) -> str:
if promoted is None:
promoted = self.has_chess960_castling_rights()
return super().board_fen(promoted=promoted)
Expand Down Expand Up @@ -799,7 +799,7 @@ def _transposition_key(self) -> Hashable:
return (super()._transposition_key(),
self.remaining_checks[chess.WHITE], self.remaining_checks[chess.BLACK])

def copy(self, stack: Union[bool, int] = True) -> Self:
def copy(self, *, stack: Union[bool, int] = True) -> Self:
board = super().copy(stack=stack)
board.remaining_checks = self.remaining_checks.copy()
if stack:
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def set_fen(self, fen: str) -> None:
self.pockets[chess.WHITE] = white_pocket
self.pockets[chess.BLACK] = black_pocket

def board_fen(self, promoted: Optional[bool] = None) -> str:
def board_fen(self, *, promoted: Optional[bool] = None) -> str:
if promoted is None:
promoted = True
return super().board_fen(promoted=promoted)
Expand All @@ -1051,7 +1051,7 @@ def epd(self, shredder: bool = False, en_passant: chess.EnPassantSpec = "legal",
board_part, info_part = epd.split(" ", 1)
return f"{board_part}[{str(self.pockets[chess.WHITE]).upper()}{self.pockets[chess.BLACK]}] {info_part}"

def copy(self, stack: Union[bool, int] = True) -> Self:
def copy(self, *, stack: Union[bool, int] = True) -> Self:
board = super().copy(stack=stack)
board.pockets[chess.WHITE] = self.pockets[chess.WHITE].copy()
board.pockets[chess.BLACK] = self.pockets[chess.BLACK].copy()
Expand Down

0 comments on commit f286d68

Please sign in to comment.