1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Removed django.utils.functional.total_ordering()

This commit is contained in:
Tim Graham
2015-06-15 10:10:40 -04:00
parent 47fcbe506c
commit 4b600ed244
8 changed files with 15 additions and 41 deletions

View File

@@ -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