Skip to content

Commit 58a54f1

Browse files
authored
Merge pull request #1013 from johndoknjas/small-cleanups
A few minor cleanups
2 parents c461118 + c3bc113 commit 58a54f1

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
@@ -1544,7 +1544,7 @@ def start(self, engine: UciProtocol) -> None:
15441544

15451545
return await self.communicate(UciConfigureCommand)
15461546

1547-
def _opponent_configuration(self, *, opponent: Optional[Opponent] = None, engine_rating: Optional[int] = None) -> ConfigMapping:
1547+
def _opponent_configuration(self, *, opponent: Optional[Opponent] = None) -> ConfigMapping:
15481548
if opponent and opponent.name and "UCI_Opponent" in self.options:
15491549
rating = opponent.rating or "none"
15501550
title = opponent.title or "none"
@@ -1554,7 +1554,7 @@ def _opponent_configuration(self, *, opponent: Optional[Opponent] = None, engine
15541554
return {}
15551555

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

15591559
def _position(self, board: chess.Board) -> None:
15601560
# Select UCI_Variant and UCI_Chess960.
@@ -1944,7 +1944,7 @@ def _chain_config(a: ConfigMapping, b: ConfigMapping) -> Iterator[Tuple[str, Con
19441944
class UciOptionMap(MutableMapping[str, T]):
19451945
"""Dictionary with case-insensitive keys."""
19461946

1947-
def __init__(self, data: Optional[Union[Iterable[Tuple[str, T]]]] = None, **kwargs: T) -> None:
1947+
def __init__(self, data: Optional[Iterable[Tuple[str, T]]] = None, **kwargs: T) -> None:
19481948
self._store: Dict[str, Tuple[str, T]] = {}
19491949
if data is None:
19501950
data = {}
@@ -1960,7 +1960,7 @@ def __delitem__(self, key: str) -> None:
19601960
del self._store[key.lower()]
19611961

19621962
def __iter__(self) -> Iterator[str]:
1963-
return (casedkey for casedkey, mappedvalue in self._store.values())
1963+
return (casedkey for casedkey, _ in self._store.values())
19641964

19651965
def __len__(self) -> int:
19661966
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)