Skip to content

Commit 4c7a902

Browse files
committed
Use typing_extensions.TypeAlias (#564)
1 parent d1dce61 commit 4c7a902

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

chess/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424

2525
from typing import ClassVar, Callable, Counter, Dict, Generic, Hashable, Iterable, Iterator, List, Literal, Mapping, Optional, SupportsInt, Tuple, Type, TypeVar, Union
2626

27+
if typing.TYPE_CHECKING:
28+
from typing_extensions import TypeAlias
29+
30+
2731
EnPassantSpec = Literal["legal", "fen", "xfen"]
2832

2933

30-
Color = bool
34+
Color: TypeAlias = bool
3135
COLORS = [WHITE, BLACK] = [True, False]
3236
ColorName = Literal["white", "black"]
3337
COLOR_NAMES: List[ColorName] = ["black", "white"]
3438

35-
PieceType = int
39+
PieceType: TypeAlias = int
3640
PIECE_TYPES = [PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING] = range(1, 7)
3741
PIECE_SYMBOLS = [None, "p", "n", "b", "r", "q", "k"]
3842
PIECE_NAMES = [None, "pawn", "knight", "bishop", "rook", "queen", "king"]
@@ -157,7 +161,7 @@ class AmbiguousMoveError(ValueError):
157161
"""Raised when the attempted move is ambiguous in the current position"""
158162

159163

160-
Square = int
164+
Square: TypeAlias = int
161165
SQUARES = [
162166
A1, B1, C1, D1, E1, F1, G1, H1,
163167
A2, B2, C2, D2, E2, F2, G2, H2,
@@ -233,7 +237,7 @@ def square_mirror(square: Square) -> Square:
233237
SQUARES_180 = [square_mirror(sq) for sq in SQUARES]
234238

235239

236-
Bitboard = int
240+
Bitboard: TypeAlias = int
237241
BB_EMPTY = 0
238242
BB_ALL = 0xffff_ffff_ffff_ffff
239243

@@ -3816,7 +3820,7 @@ def __repr__(self) -> str:
38163820
return f"<LegalMoveGenerator at {id(self):#x} ({sans})>"
38173821

38183822

3819-
IntoSquareSet = Union[SupportsInt, Iterable[Square]]
3823+
IntoSquareSet: TypeAlias = Union[SupportsInt, Iterable[Square]]
38203824

38213825
class SquareSet:
38223826
"""

0 commit comments

Comments
 (0)