Commit 1006bd45 authored by Raymond Hettinger's avatar Raymond Hettinger

Future proof total_ordering against changes in methods defined on object.

parent 2e55fec1
...@@ -82,7 +82,7 @@ def total_ordering(cls): ...@@ -82,7 +82,7 @@ def total_ordering(cls):
('__lt__', lambda self, other: not self >= other)] ('__lt__', lambda self, other: not self >= other)]
} }
# Find comparisons not inherited from object. # 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: if not roots:
raise ValueError('must define at least one ordering operation: < > <= >=') raise ValueError('must define at least one ordering operation: < > <= >=')
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__ root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment