mirror of
https://github.com/django/django.git
synced 2025-09-18 00:10:22 +00:00
Got rid of old __cmp__methods replaced by rich comparison.
The __cmp__ methods are unsupported in Python 3. _doctest.py has been left untouched because it is likely it will not be migrated to Python 3.
This commit is contained in:
parent
45f55a9fcc
commit
d04f72fb31
5 changed files with 69 additions and 29 deletions
|
@ -58,6 +58,7 @@ def lazy(func, *resultclasses):
|
|||
function is evaluated on every access.
|
||||
"""
|
||||
|
||||
@total_ordering
|
||||
class __proxy__(Promise):
|
||||
"""
|
||||
Encapsulate a function call and act as a proxy for methods that are
|
||||
|
@ -124,17 +125,23 @@ def lazy(func, *resultclasses):
|
|||
def __str_cast(self):
|
||||
return str(func(*self.__args, **self.__kw))
|
||||
|
||||
def __cmp__(self, rhs):
|
||||
def __cast(self):
|
||||
if self._delegate_str:
|
||||
s = str(func(*self.__args, **self.__kw))
|
||||
return self.__str_cast()
|
||||
elif self._delegate_unicode:
|
||||
s = unicode(func(*self.__args, **self.__kw))
|
||||
return self.__unicode_cast()
|
||||
else:
|
||||
s = func(*self.__args, **self.__kw)
|
||||
if isinstance(rhs, Promise):
|
||||
return -cmp(rhs, s)
|
||||
else:
|
||||
return cmp(s, rhs)
|
||||
return func(*self.__args, **self.__kw)
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Promise):
|
||||
other = other.__cast()
|
||||
return self.__cast() == other
|
||||
|
||||
def __lt__(self, other):
|
||||
if isinstance(other, Promise):
|
||||
other = other.__cast()
|
||||
return self.__cast() < other
|
||||
|
||||
def __mod__(self, rhs):
|
||||
if self._delegate_str:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue