Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/pygambit/game.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ class GamePlayers:
raise ValueError(f"Game has multiple players with label '{index}'")
return matches[0]
if isinstance(index, int):
return Player.wrap(self.game.deref().GetPlayer(index + 1))
try:
return Player.wrap(self.game.deref().GetPlayer(index + 1))
except IndexError:
raise IndexError("Index out of range") from None
raise TypeError(f"Player index must be int or str, not {index.__class__.__name__}")

@property
Expand Down
7 changes: 4 additions & 3 deletions tests/test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ def test_player_index_by_string():
def test_player_index_out_of_range():
game = gbt.Game.new_table([2, 2])
assert len(game.players) == 2
with pytest.raises(IndexError):
exp_error_msg = "Index out of range"
with pytest.raises(IndexError, match=exp_error_msg):
_ = game.players[2]
with pytest.raises(IndexError):
with pytest.raises(IndexError, match=exp_error_msg):
_ = game.players[3]
with pytest.raises(IndexError):
with pytest.raises(IndexError, match=exp_error_msg):
_ = game.players[-1]


Expand Down