diff --git a/src/diana/sgfparser/collection.py b/src/diana/sgfparser/collection.py --- a/src/diana/sgfparser/collection.py +++ b/src/diana/sgfparser/collection.py @@ -4,6 +4,8 @@ from .game_record import GameRecord class Collection: + """Game collection type, a list of game trees.""" + def __init__(self, s): self.game_trees = [] i = skip_whitespace(s, 0) @@ -18,6 +20,7 @@ class Collection: raise ParserError("expected EOF", s, i) def list_games(self): + """:rtype: Iterator[GameRecord]""" for tree in self.game_trees: for game in tree.list_games(): yield game @@ -30,10 +33,21 @@ class GameTree: @staticmethod def fits(s, i): + """Decide if a GameTree fits at the suggested string location. + + :param str s: an SGF string + :param int i: a string location + :return: True if there might be a GameTree at the location, False if not""" return i < len(s) and s[i] == "(" @staticmethod def create(s, start): + """Create a GameTree from the string and move the current position pointer. + + :param str s: an SGF string + :param int start: a location in s + :return: the resulting tree and a pointer to its end + :rtype: (int, GameTree)""" assert GameTree.fits(s, start) res = GameTree() @@ -65,8 +79,8 @@ class GameTree: i = skip_whitespace(s, i + 1) return (i, res) - ## Expand multiple games into distinct GameTrees and yield each. def list_games(self): + """Expand multiple games into distinct GameTrees and yield each.""" if len(self.nodes) == 0: return None for node in self.nodes[0].list_gi_nodes(): @@ -77,10 +91,10 @@ class GameTree: return self.nodes[i] return None - ## Create and return a new game tree containing the provided Node. - # - # Ancestor nodes are copied, descendants are moved from the seed_node. def _build_subtree(self, seed_node): + """Create and return a new game tree containing the provided Node. + + Ancestor nodes are copied, descendants are moved from the seed_node.""" node = seed_node.copy() node.set_children(seed_node.children) seed_node.children = []