diff options
author | Raymond Hettinger <python@rcn.com> | 2011-01-08 07:01:56 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-01-08 07:01:56 (GMT) |
commit | 23f9fc344827c02cf2450f7e0903681e69db201a (patch) | |
tree | c0454c2980f0a3f768597b5e4f54896ad8970ca3 /Lib/functools.py | |
parent | 06ec45e2f8108d6bfc1fa8abe80de94bc4eeb8a3 (diff) | |
download | cpython-23f9fc344827c02cf2450f7e0903681e69db201a.zip cpython-23f9fc344827c02cf2450f7e0903681e69db201a.tar.gz cpython-23f9fc344827c02cf2450f7e0903681e69db201a.tar.bz2 |
Issue #10042: Fixed the total_ordering decorator to handle cross-type
comparisons that could lead to infinite recursion.
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index d450634..1062a45 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -68,17 +68,17 @@ def wraps(wrapped, def total_ordering(cls): """Class decorator that fills in missing ordering methods""" convert = { - '__lt__': [('__gt__', lambda self, other: other < self), - ('__le__', lambda self, other: not other < self), + '__lt__': [('__gt__', lambda self, other: not (self < other or self == other)), + ('__le__', lambda self, other: self < other or self == other), ('__ge__', lambda self, other: not self < other)], - '__le__': [('__ge__', lambda self, other: other <= self), - ('__lt__', lambda self, other: not other <= self), + '__le__': [('__ge__', lambda self, other: not self <= other or self == other), + ('__lt__', lambda self, other: self <= other and not self == other), ('__gt__', lambda self, other: not self <= other)], - '__gt__': [('__lt__', lambda self, other: other > self), - ('__ge__', lambda self, other: not other > self), + '__gt__': [('__lt__', lambda self, other: not (self > other or self == other)), + ('__ge__', lambda self, other: self > other or self == other), ('__le__', lambda self, other: not self > other)], - '__ge__': [('__le__', lambda self, other: other >= self), - ('__gt__', lambda self, other: not other >= self), + '__ge__': [('__le__', lambda self, other: (not self >= other) or self == other), + ('__gt__', lambda self, other: self >= other and not self == other), ('__lt__', lambda self, other: not self >= other)] } # Find user-defined comparisons (not those inherited from object). |