From 4c7a9025e3442fb75a14eae367fd88200e210042 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Thu, 18 Apr 2024 17:40:45 +0200 Subject: [PATCH] Use typing_extensions.TypeAlias (#564) --- chess/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/chess/__init__.py b/chess/__init__.py index a9328a04b..9eeb2c5e2 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -24,15 +24,19 @@ from typing import ClassVar, Callable, Counter, Dict, Generic, Hashable, Iterable, Iterator, List, Literal, Mapping, Optional, SupportsInt, Tuple, Type, TypeVar, Union +if typing.TYPE_CHECKING: + from typing_extensions import TypeAlias + + EnPassantSpec = Literal["legal", "fen", "xfen"] -Color = bool +Color: TypeAlias = bool COLORS = [WHITE, BLACK] = [True, False] ColorName = Literal["white", "black"] COLOR_NAMES: List[ColorName] = ["black", "white"] -PieceType = int +PieceType: TypeAlias = int PIECE_TYPES = [PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING] = range(1, 7) PIECE_SYMBOLS = [None, "p", "n", "b", "r", "q", "k"] PIECE_NAMES = [None, "pawn", "knight", "bishop", "rook", "queen", "king"] @@ -157,7 +161,7 @@ class AmbiguousMoveError(ValueError): """Raised when the attempted move is ambiguous in the current position""" -Square = int +Square: TypeAlias = int SQUARES = [ A1, B1, C1, D1, E1, F1, G1, H1, A2, B2, C2, D2, E2, F2, G2, H2, @@ -233,7 +237,7 @@ def square_mirror(square: Square) -> Square: SQUARES_180 = [square_mirror(sq) for sq in SQUARES] -Bitboard = int +Bitboard: TypeAlias = int BB_EMPTY = 0 BB_ALL = 0xffff_ffff_ffff_ffff @@ -3816,7 +3820,7 @@ def __repr__(self) -> str: return f"" -IntoSquareSet = Union[SupportsInt, Iterable[Square]] +IntoSquareSet: TypeAlias = Union[SupportsInt, Iterable[Square]] class SquareSet: """