Skip to content

Commit

Permalink
Towards passing pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 13, 2024
1 parent 6228bac commit e204169
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ def _set_chess960_pos(self, scharnagl: int) -> None:
n, bb = divmod(n, 4)
n, q = divmod(n, 6)

n1 = 0
n2 = 0
for n1 in range(0, 4):
n2 = n + (3 - n1) * (4 - n1) // 2 - 5
if n1 < n2 and 1 <= n2 <= 4:
Expand Down Expand Up @@ -2394,7 +2396,7 @@ def push(self, move: Move) -> None:
elif move.to_square == ep_square and abs(diff) in [7, 9] and not captured_piece_type:
# Remove pawns captured en passant.
down = -8 if self.turn == WHITE else 8
capture_square = ep_square + down
capture_square = move.to_square + down
captured_piece_type = self._remove_piece_at(capture_square)

# Promotion.
Expand Down Expand Up @@ -3166,6 +3168,8 @@ def parse_san(self, san: str) -> Move:

# Filter by original square.
from_mask = BB_ALL
from_file = None
from_rank = None
if match.group(2):
from_file = FILE_NAMES.index(match.group(2))
from_mask &= BB_FILES[from_file]
Expand All @@ -3177,7 +3181,7 @@ def parse_san(self, san: str) -> Move:
if match.group(1):
piece_type = PIECE_SYMBOLS.index(match.group(1).lower())
from_mask &= self.pieces_mask(piece_type, self.turn)
elif match.group(2) and match.group(3):
elif from_file is not None and from_rank is not None:
# Allow fully specified moves, even if they are not pawn moves,
# including castling moves.
move = self.find_move(square(from_file, from_rank), to_square, promotion)
Expand All @@ -3189,7 +3193,7 @@ def parse_san(self, san: str) -> Move:
from_mask &= self.pawns

# Do not allow pawn captures if file is not specified.
if not match.group(2):
if from_file is None:
from_mask &= BB_FILES[square_file(to_square)]

# Match legal moves.
Expand Down
2 changes: 1 addition & 1 deletion chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def get_pipe_transport(self, fd: int) -> Optional[asyncio.BaseTransport]:
assert fd == 0, f"expected 0 for stdin, got {fd}"
return self

def write(self, data: bytes) -> None:
def write(self, data: bytes | bytearray | memoryview) -> None:
self.stdin_buffer.extend(data)
while b"\n" in self.stdin_buffer:
line_bytes, self.stdin_buffer = self.stdin_buffer.split(b"\n", 1)
Expand Down
1 change: 1 addition & 0 deletions chess/syzygy.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ def encode_piece(self, norm: List[int], pos: List[chess.Square], factor: List[in
for i in range(n):
pos[i] ^= 0x38

i = 0
for i in range(n):
if offdiag(pos[i]):
break
Expand Down

0 comments on commit e204169

Please sign in to comment.