Remove integer indexing from game collections in pygambit#942
Open
d-kad wants to merge 20 commits into
Open
Conversation
iteration and tuple unpacking in quickstart, stripped-down poker, and OpenSpiel tutorials.
Players, outcomes, strategies, infosets, actions, infoset members and Node.children are indexed by str label only. Integer indexing raises TypeError with a 16.7.0 migration message; unknown labels raise KeyError; lookup is by exact match, with no whitespace stripping. Contingency indexing on Game is unchanged.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Contributor
Author
|
Design question — should label lookup strip whitespace, or match exactly? Before this PR, the collection matches = [x for x in self if x.label == index.strip()]This appears at 10 sites ( In this PR I matched labels exactly. ~~ (superseded — see update) UPD: @rahulsavani and I agreed label lookup should keep stripping surrounding |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Game object collections in
pygambitare now indexed by string label only.Game.players,Game.outcomes,Game.strategies,Game.infosets,Game.actions,Player.strategies,Player.infosets,Player.actions,Infoset.actions,Infoset.members,and
Node.children. Indexing by an integer raisesTypeErrorwith a migration message.Positional access remains available by iterating a collection (e.g.
pl1, pl2 = game.players).Indexing a
Gameby a contingency (e.g.game[0, 1]) is unchanged.(existing behavior, now centralised and pinned by a test).
A label matching no object uniformly raises
KeyError(Node.childrenpreviously raisedValueError)._resolve_by_labelhelper; all the collection__getitem__methods use it.The
labelparameter is deliberately unannotated so the migrationTypeErroris reachable(a
strannotation would compile to an enforced check in Cython).with new tests added pinning the integer-rejection message and exact-match lookup across all collections
(
COLLECTION_GETTERSintests/test_game.py).