mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-05 04:34:10 +00:00
Fix comparison of NummedObj against non-NummedObj
Previously this would explode with AttributeError.
This commit is contained in:
parent
fc62fd31a0
commit
6ca328ba94
@ -1,7 +1,9 @@
|
|||||||
import collections, itertools
|
import collections, itertools, functools
|
||||||
|
|
||||||
objnums = collections.defaultdict(itertools.count)
|
objnums = collections.defaultdict(itertools.count)
|
||||||
|
|
||||||
|
|
||||||
|
@functools.total_ordering
|
||||||
class NummedObj(object):
|
class NummedObj(object):
|
||||||
"""
|
"""
|
||||||
This is useful for nicer debug printouts. Instead of objects of the same class being
|
This is useful for nicer debug printouts. Instead of objects of the same class being
|
||||||
@ -27,22 +29,14 @@ class NummedObj(object):
|
|||||||
return "<%s #%d>" % (self._classname, self._objid,)
|
return "<%s #%d>" % (self._classname, self._objid,)
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
if isinstance(other, NummedObj):
|
||||||
return (self._objid, self._classname,) < (other._objid, other._classname,)
|
return (self._objid, self._classname,) < (other._objid, other._classname,)
|
||||||
|
return NotImplemented
|
||||||
def __le__(self, other):
|
|
||||||
return (self._objid, self._classname,) <= (other._objid, other._classname,)
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
if isinstance(other, NummedObj):
|
||||||
return (self._objid, self._classname,) == (other._objid, other._classname,)
|
return (self._objid, self._classname,) == (other._objid, other._classname,)
|
||||||
|
return NotImplemented
|
||||||
def __ne__(self, other):
|
|
||||||
return (self._objid, self._classname,) != (other._objid, other._classname,)
|
|
||||||
|
|
||||||
def __gt__(self, other):
|
|
||||||
return (self._objid, self._classname,) > (other._objid, other._classname,)
|
|
||||||
|
|
||||||
def __ge__(self, other):
|
|
||||||
return (self._objid, self._classname,) >= (other._objid, other._classname,)
|
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return id(self)
|
return id(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user