summaryrefslogtreecommitdiff
path: root/django/utils/functional.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-06-15 10:10:40 -0400
committerTim Graham <timograham@gmail.com>2015-06-15 13:15:24 -0400
commit4b600ed24488b2d1fc0fd59fc883a84ee745fcf8 (patch)
tree0652c5a7f50fcbcd640bfbee41a9a4bfc217e362 /django/utils/functional.py
parent47fcbe506c04019a12e16221843e25a52249b1ab (diff)
Removed django.utils.functional.total_ordering()
Diffstat (limited to 'django/utils/functional.py')
-rw-r--r--django/utils/functional.py36
1 files changed, 1 insertions, 35 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 84f4227784..bade67de46 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -1,7 +1,6 @@
import copy
import operator
-import sys
-from functools import wraps
+from functools import total_ordering, wraps
from django.utils import six
from django.utils.six.moves import copyreg
@@ -385,36 +384,3 @@ def partition(predicate, values):
for item in values:
results[predicate(item)].append(item)
return results
-
-if sys.version_info >= (2, 7, 2):
- from functools import total_ordering
-else:
- # For Python < 2.7.2. total_ordering in versions prior to 2.7.2 is buggy.
- # See http://bugs.python.org/issue10042 for details. For these versions use
- # code borrowed from Python 2.7.3.
- def total_ordering(cls):
- """Class decorator that fills in missing ordering methods"""
- convert = {
- '__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: 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: 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: (not self >= other) or self == other),
- ('__gt__', lambda self, other: self >= other and not self == other),
- ('__lt__', lambda self, other: not self >= other)]
- }
- roots = set(dir(cls)) & set(convert)
- if not roots:
- raise ValueError('must define at least one ordering operation: < > <= >=')
- root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
- for opname, opfunc in convert[root]:
- if opname not in roots:
- opfunc.__name__ = opname
- opfunc.__doc__ = getattr(int, opname).__doc__
- setattr(cls, opname, opfunc)
- return cls