Skip to content

Commit

Permalink
Provide type hints for empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Sep 30, 2023
1 parent 6f4d35a commit 15e3584
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ def _carry_rippler(mask: Bitboard) -> Iterator[Bitboard]:
break

def _attack_table(deltas: List[int]) -> Tuple[List[Bitboard], List[Dict[Bitboard, Bitboard]]]:
mask_table = []
attack_table = []
mask_table: List[Bitboard] = []
attack_table: List[Dict[Bitboard, Bitboard]] = []

for square in SQUARES:
attacks = {}
Expand All @@ -433,9 +433,9 @@ def _attack_table(deltas: List[int]) -> Tuple[List[Bitboard], List[Dict[Bitboard


def _rays() -> List[List[Bitboard]]:
rays = []
rays: List[List[Bitboard]] = []
for a, bb_a in enumerate(BB_SQUARES):
rays_row = []
rays_row: List[Bitboard] = []
for b, bb_b in enumerate(BB_SQUARES):
if BB_DIAG_ATTACKS[a][0] & bb_b:
rays_row.append((BB_DIAG_ATTACKS[a][0] & BB_DIAG_ATTACKS[b][0]) | bb_a | bb_b)
Expand Down Expand Up @@ -961,7 +961,7 @@ def board_fen(self, *, promoted: Optional[bool] = False) -> str:
Gets the board FEN (e.g.,
``rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR``).
"""
builder = []
builder: List[str] = []
empty = 0

for square in SQUARES_180:
Expand Down Expand Up @@ -1056,7 +1056,7 @@ def piece_map(self, *, mask: Bitboard = BB_ALL) -> Dict[Square, Piece]:
"""
Gets a dictionary of :class:`pieces <chess.Piece>` by square index.
"""
result = {}
result: Dict[Square, Piece] = {}
for square in scan_reversed(self.occupied & mask):
result[square] = typing.cast(Piece, self.piece_at(square))
return result
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({self.board_fen()!r})"

def __str__(self) -> str:
builder = []
builder: List[str] = []

for square in SQUARES_180:
piece = self.piece_at(square)
Expand All @@ -1251,7 +1251,7 @@ def unicode(self, *, invert_color: bool = False, borders: bool = False, empty_sq
:param invert_color: Invert color of the Unicode pieces.
:param borders: Show borders and a coordinate margin.
"""
builder = []
builder: List[str] = []
for rank_index in (range(7, -1, -1) if orientation else range(8)):
if borders:
builder.append(" ")
Expand Down Expand Up @@ -2094,7 +2094,7 @@ def can_claim_threefold_repetition(self) -> bool:
transpositions.update((transposition_key, ))

# Count positions.
switchyard = []
switchyard: List[Move] = []
while self.move_stack:
move = self.pop()
switchyard.append(move)
Expand Down Expand Up @@ -2147,7 +2147,7 @@ def is_repetition(self, count: int = 3) -> bool:

# Check full replay.
transposition_key = self._transposition_key()
switchyard = []
switchyard: List[Move] = []

try:
while True:
Expand Down Expand Up @@ -2343,7 +2343,7 @@ def castling_shredder_fen(self) -> str:
if not castling_rights:
return "-"

builder = []
builder: List[str] = []

for square in scan_reversed(castling_rights & BB_RANK_1):
builder.append(FILE_NAMES[square_file(square)].upper())
Expand All @@ -2354,7 +2354,7 @@ def castling_shredder_fen(self) -> str:
return "".join(builder)

def castling_xfen(self) -> str:
builder = []
builder: List[str] = []

for color in COLORS:
king = self.king(color)
Expand Down Expand Up @@ -2615,7 +2615,7 @@ def chess960_pos(self, *, ignore_turn: bool = False, ignore_castling: bool = Fal
return super().chess960_pos()

def _epd_operations(self, operations: Mapping[str, Union[None, str, int, float, Move, Iterable[Move]]]) -> str:
epd = []
epd: List[str] = []
first_op = True

for opcode, operand in operations.items():
Expand Down Expand Up @@ -2786,7 +2786,7 @@ def _parse_epd_ops(self: BoardT, operation_part: str, make_board: Callable[[], B

if opcode == "pv":
# A variation.
variation = []
variation: List[Move] = []
for token in operand.split():
move = position.parse_xboard(token)
variation.append(move)
Expand Down Expand Up @@ -2963,7 +2963,7 @@ def variation_san(self, variation: Iterable[Move]) -> str:
:raises: :exc:`IllegalMoveError` if any moves in the sequence are illegal.
"""
board = self.copy(stack=False)
san = []
san: List[str] = []

for move in variation:
if not board.is_legal(move):
Expand Down Expand Up @@ -3781,7 +3781,7 @@ def __contains__(self, move: Move) -> bool:
return self.board.is_pseudo_legal(move)

def __repr__(self) -> str:
builder = []
builder: List[str] = []

for move in self:
if self.board.is_legal(move):
Expand Down Expand Up @@ -3898,7 +3898,7 @@ class SquareSet:

def __init__(self, squares: IntoSquareSet = BB_EMPTY) -> None:
try:
self.mask = squares.__int__() & BB_ALL # type: ignore
self.mask: Bitboard = squares.__int__() & BB_ALL # type: ignore
return
except AttributeError:
self.mask = 0
Expand Down Expand Up @@ -4095,7 +4095,7 @@ def __repr__(self) -> str:
return f"SquareSet({self.mask:#021_x})"

def __str__(self) -> str:
builder = []
builder: List[str] = []

for square in SQUARES_180:
mask = BB_SQUARES[square]
Expand Down

0 comments on commit 15e3584

Please sign in to comment.