Skip to content

Add some missing docstrings #1143

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

Merged
merged 1 commit into from
Apr 6, 2025
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
21 changes: 21 additions & 0 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,11 +1810,13 @@ def ply(self) -> int:
return 2 * (self.fullmove_number - 1) + (self.turn == BLACK)

def remove_piece_at(self, square: Square) -> Optional[Piece]:
"""Remove a piece, if any, from the given square and return the removed piece."""
piece = super().remove_piece_at(square)
self.clear_stack()
return piece

def set_piece_at(self, square: Square, piece: Optional[Piece], promoted: bool = False) -> None:
"""Place a piece on a square."""
super().set_piece_at(square, piece, promoted=promoted)
self.clear_stack()

Expand Down Expand Up @@ -1998,6 +2000,7 @@ def is_pseudo_legal(self, move: Move) -> bool:
return bool(self.attacks_mask(move.from_square) & to_mask)

def is_legal(self, move: Move) -> bool:
"""Check if a move is legal in the current position."""
return not self.is_variant_end() and self.is_pseudo_legal(move) and not self.is_into_check(move)

def is_variant_end(self) -> bool:
Expand Down Expand Up @@ -2034,9 +2037,27 @@ def is_variant_draw(self) -> bool:
return False

def is_game_over(self, *, claim_draw: bool = False) -> bool:
"""
Check if the game is over by any rule.

The game is not considered to be over by the
:func:`fifty-move rule <chess.Board.can_claim_fifty_moves()>` or
:func:`threefold repetition <chess.Board.can_claim_threefold_repetition()>`,
unless *claim_draw* is given. Note that checking the latter can be
slow.
"""
return self.outcome(claim_draw=claim_draw) is not None

def result(self, *, claim_draw: bool = False) -> str:
"""
Return the result of a game: 1-0, 0-1, 1/2-1/2, or *.

The game is not considered to be over by the
:func:`fifty-move rule <chess.Board.can_claim_fifty_moves()>` or
:func:`threefold repetition <chess.Board.can_claim_threefold_repetition()>`,
unless *claim_draw* is given. Note that checking the latter can be
slow.
"""
outcome = self.outcome(claim_draw=claim_draw)
return outcome.result() if outcome else "*"

Expand Down