Skip to content

Commit 5fa6fc6

Browse files
committed
Now do a proper FutureWarning on setting a player to have the same label as another.
1 parent 84d5d99 commit 5fa6fc6

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/pygambit/action.pxi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class Action:
7777

7878
@label.setter
7979
def label(self, value: str) -> None:
80-
if (value == "" or value.encode("ascii") in
81-
(action.deref().GetLabel()
82-
for action in self.action.deref().GetInfoset().deref().GetActions())):
80+
if value == self.label:
81+
return
82+
if value == "" or value in (act.label for act in self.infoset.actions):
8383
warnings.warn("In a future version, actions must have unique labels "
8484
"within their information set",
8585
FutureWarning)

src/pygambit/player.pxi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ class Player:
192192

193193
@label.setter
194194
def label(self, value: str) -> None:
195-
# check to see if the player's name has been used elsewhere
196-
if value in [i.label for i in self.game.players]:
197-
warnings.warn("Another player with an identical label exists")
195+
if value == self.label:
196+
return
197+
if value == "" or value in (player.label for player in self.game.players):
198+
warnings.warn("In a future version, players must have unique labels",
199+
FutureWarning)
198200
self.player.deref().SetLabel(value.encode("ascii"))
199201

200202
@property

tests/test_players.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ def test_player_label_invalid():
6161
_ = game.players["Not a player"]
6262

6363

64+
def test_set_empty_player_futurewarning():
65+
game = games.create_stripped_down_poker_efg()
66+
with pytest.warns(FutureWarning):
67+
game.players[0].label = ""
68+
69+
70+
def test_set_duplicate_player_futurewarning():
71+
game = games.create_stripped_down_poker_efg()
72+
with pytest.warns(FutureWarning):
73+
game.players[0].label = game.players[1].label
74+
75+
6476
def test_strategic_game_add_player():
6577
game = gbt.Game.new_table([2, 2])
6678
game.add_player()

0 commit comments

Comments
 (0)