Future proof total_ordering against changes in methods defined on object.

This commit is contained in:
Raymond Hettinger 2010-09-14 22:55:13 +00:00
parent 2e55fec14c
commit 1006bd459b
1 changed files with 1 additions and 1 deletions

View File

@ -82,7 +82,7 @@ def total_ordering(cls):
('__lt__', lambda self, other: not self >= other)]
}
# Find comparisons not inherited from object.
roots = [op for op in convert if getattr(cls, op) is not getattr(object, op)]
roots = [op for op in convert if getattr(cls, op, None) is not getattr(object, op, None)]
if not roots:
raise ValueError('must define at least one ordering operation: < > <= >=')
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__