Skip to content

Commit

Permalink
Edge is read-only, added Loop subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Nov 15, 2017
1 parent 7cf61bb commit 78d0438
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions graphi/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ def __class__(self):
def __getitem__(self, index):
return [self.start, self.stop][index]

def __setitem__(self, index, value):
if index == 1:
self.start = value
elif index == 2:
self.stop = value
else:
raise IndexError('Edge assignment index out of range')

def __iter__(self):
yield self.start
yield self.stop
Expand All @@ -94,3 +86,20 @@ def __str__(self):

def __repr__(self):
return '%s[%r:%r]' % (type(self).__name__, self.start, self.stop)


class Loop(Edge):
"""
An edge in a graph from a node to itself
:param start: the start or tail of a loop
:param stop: optional stop or head of a loop, same as start
:param step: currently unused
:raises ValueError: if ``stop`` is given but not equal to ``start``
"""
def __init__(self, start, stop=None, step=None):
stop = start if stop is None else stop
if start != stop:
raise ValueError('%s start and stop node must be equal' % self.__class__.__name__)
super(Loop, self).__init__(start, stop, step)

0 comments on commit 78d0438

Please sign in to comment.