Source code for priops.priop

[docs]class Priop(list): """A graph of edges."""
[docs] def __init__(self, name=None, *args, **kwargs): """Sets up a new Priop named *name* (optional). The constructor accepts all the various formats that ``list`` accepts.""" list.__init__(self, *args, **kwargs) self.name = name
[docs] def __str__(self): """Returns a pretty-formatted string (human readable), describing the Priop.""" return '(' + self.name + ', defined by:\n ' + \ '\n* '.join(map(str, self)) + '\n)'
[docs] def __add__(self, other_priop): """Concatenates both the list items as well as the names. If the names are the same, the name is kept.""" if self.name == other_priop.name: return Priop(list.__add__(self, other_priop), name=self.name) else: return Priop(list.__add__(self, other_priop), name=', '.join([self.name, other_priop.name]))