From: Raymond Hettinger Date: Tue, 14 Sep 2010 22:55:13 +0000 (+0000) Subject: Future proof total_ordering against changes in methods defined on object. X-Git-Tag: v3.2a3~261 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1006bd459bc1cdd2aeb1762fadc6cc64d62c819f;p=python Future proof total_ordering against changes in methods defined on object. --- diff --git a/Lib/functools.py b/Lib/functools.py index b39e77eb61..314c0dd906 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -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__