implement __lt__ and __eq__ to support sorting a list of types

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-11-01 22:20:46 +01:00
parent 7b9ff27356
commit bf1b995908
1 changed files with 6 additions and 0 deletions

View File

@ -86,6 +86,12 @@ class Type(object):
def __repr__(self):
return '<Type %s>' % self.name
def __eq__(self, other):
return isinstance(other, self.__class__) and self.name == other.name
def __lt__(self, other):
return isinstance(other, self.__class__) and self.name < other.name
@property
def is_singleton(self):
"""Check whether a type is a singleton."""