Skip to content

Commit c3bc113

Browse files
committed
Small cleanups.
1 parent 736478a commit c3bc113

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

chess/engine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ def start(self, engine: UciProtocol) -> None:
15321532

15331533
return await self.communicate(UciConfigureCommand)
15341534

1535-
def _opponent_configuration(self, *, opponent: Optional[Opponent] = None, engine_rating: Optional[int] = None) -> ConfigMapping:
1535+
def _opponent_configuration(self, *, opponent: Optional[Opponent] = None) -> ConfigMapping:
15361536
if opponent and opponent.name and "UCI_Opponent" in self.options:
15371537
rating = opponent.rating or "none"
15381538
title = opponent.title or "none"
@@ -1542,7 +1542,7 @@ def _opponent_configuration(self, *, opponent: Optional[Opponent] = None, engine
15421542
return {}
15431543

15441544
async def send_opponent_information(self, *, opponent: Optional[Opponent] = None, engine_rating: Optional[int] = None) -> None:
1545-
return await self.configure(self._opponent_configuration(opponent=opponent, engine_rating=engine_rating))
1545+
return await self.configure(self._opponent_configuration(opponent=opponent))
15461546

15471547
def _position(self, board: chess.Board) -> None:
15481548
# Select UCI_Variant and UCI_Chess960.
@@ -1932,7 +1932,7 @@ def _chain_config(a: ConfigMapping, b: ConfigMapping) -> Iterator[Tuple[str, Con
19321932
class UciOptionMap(MutableMapping[str, T]):
19331933
"""Dictionary with case-insensitive keys."""
19341934

1935-
def __init__(self, data: Optional[Union[Iterable[Tuple[str, T]]]] = None, **kwargs: T) -> None:
1935+
def __init__(self, data: Optional[Iterable[Tuple[str, T]]] = None, **kwargs: T) -> None:
19361936
self._store: Dict[str, Tuple[str, T]] = {}
19371937
if data is None:
19381938
data = {}
@@ -1948,7 +1948,7 @@ def __delitem__(self, key: str) -> None:
19481948
del self._store[key.lower()]
19491949

19501950
def __iter__(self) -> Iterator[str]:
1951-
return (casedkey for casedkey, mappedvalue in self._store.values())
1951+
return (casedkey for casedkey, _ in self._store.values())
19521952

19531953
def __len__(self) -> int:
19541954
return len(self._store)

chess/pgn.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,7 @@ def __setitem__(self, key: str, value: str) -> None:
942942
self._others[key] = value
943943

944944
def __getitem__(self, key: str) -> str:
945-
if key in TAG_ROSTER:
946-
return self._tag_roster[key]
947-
else:
948-
return self._others[key]
945+
return self._tag_roster[key] if key in TAG_ROSTER else self._others[key]
949946

950947
def __delitem__(self, key: str) -> None:
951948
if key in TAG_ROSTER:

chess/polyglot.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,8 @@ def __getitem__(self, index: int) -> Entry:
391391
return Entry(key, raw_move, weight, learn, move)
392392

393393
def __iter__(self) -> Iterator[Entry]:
394-
i = 0
395-
size = len(self)
396-
while i < size:
394+
for i in range(len(self)):
397395
yield self[i]
398-
i += 1
399396

400397
def bisect_key_left(self, key: int) -> int:
401398
lo = 0

0 commit comments

Comments
 (0)