Skip to content

Commit

Permalink
Merge pull request #1013 from johndoknjas/small-cleanups
Browse files Browse the repository at this point in the history
A few minor cleanups
  • Loading branch information
niklasf committed Jul 8, 2023
2 parents c461118 + c3bc113 commit 58a54f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
8 changes: 4 additions & 4 deletions chess/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ def start(self, engine: UciProtocol) -> None:

return await self.communicate(UciConfigureCommand)

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

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

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

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

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

def __len__(self) -> int:
return len(self._store)
Expand Down
5 changes: 1 addition & 4 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,7 @@ def __setitem__(self, key: str, value: str) -> None:
self._others[key] = value

def __getitem__(self, key: str) -> str:
if key in TAG_ROSTER:
return self._tag_roster[key]
else:
return self._others[key]
return self._tag_roster[key] if key in TAG_ROSTER else self._others[key]

def __delitem__(self, key: str) -> None:
if key in TAG_ROSTER:
Expand Down
5 changes: 1 addition & 4 deletions chess/polyglot.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,8 @@ def __getitem__(self, index: int) -> Entry:
return Entry(key, raw_move, weight, learn, move)

def __iter__(self) -> Iterator[Entry]:
i = 0
size = len(self)
while i < size:
for i in range(len(self)):
yield self[i]
i += 1

def bisect_key_left(self, key: int) -> int:
lo = 0
Expand Down

0 comments on commit 58a54f1

Please sign in to comment.