summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-05-13 04:26:37 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-05-13 04:26:37 (GMT)
commitffcd8490d04727ff2a45f380b27e437c0c9e49f4 (patch)
tree7d23ed98166be6a57b1948b1ec148c23f4b7720a /Lib/functools.py
parent276e9c841d6b0a8aa0caf727fd54763fcc8d13f7 (diff)
downloadcpython-ffcd8490d04727ff2a45f380b27e437c0c9e49f4.zip
cpython-ffcd8490d04727ff2a45f380b27e437c0c9e49f4.tar.gz
cpython-ffcd8490d04727ff2a45f380b27e437c0c9e49f4.tar.bz2
Reduce the overhead in functools.total_ordering by localizing NotImplemented.
(Sugguested by Serhiy Storchaka)
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 91e9685..fb2e4bd 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -94,80 +94,80 @@ def wraps(wrapped,
# infinite recursion that could occur when the operator dispatch logic
# detects a NotImplemented result and then calls a reflected method.
-def _gt_from_lt(self, other):
+def _gt_from_lt(self, other, NotImplemented=NotImplemented):
'Return a > b. Computed by @total_ordering from (not a < b) and (a != b).'
op_result = self.__lt__(other)
if op_result is NotImplemented:
return op_result
return not op_result and self != other
-def _le_from_lt(self, other):
+def _le_from_lt(self, other, NotImplemented=NotImplemented):
'Return a <= b. Computed by @total_ordering from (a < b) or (a == b).'
op_result = self.__lt__(other)
return op_result or self == other
-def _ge_from_lt(self, other):
+def _ge_from_lt(self, other, NotImplemented=NotImplemented):
'Return a >= b. Computed by @total_ordering from (not a < b).'
op_result = self.__lt__(other)
if op_result is NotImplemented:
return op_result
return not op_result
-def _ge_from_le(self, other):
+def _ge_from_le(self, other, NotImplemented=NotImplemented):
'Return a >= b. Computed by @total_ordering from (not a <= b) or (a == b).'
op_result = self.__le__(other)
if op_result is NotImplemented:
return op_result
return not op_result or self == other
-def _lt_from_le(self, other):
+def _lt_from_le(self, other, NotImplemented=NotImplemented):
'Return a < b. Computed by @total_ordering from (a <= b) and (a != b).'
op_result = self.__le__(other)
if op_result is NotImplemented:
return op_result
return op_result and self != other
-def _gt_from_le(self, other):
+def _gt_from_le(self, other, NotImplemented=NotImplemented):
'Return a > b. Computed by @total_ordering from (not a <= b).'
op_result = self.__le__(other)
if op_result is NotImplemented:
return op_result
return not op_result
-def _lt_from_gt(self, other):
+def _lt_from_gt(self, other, NotImplemented=NotImplemented):
'Return a < b. Computed by @total_ordering from (not a > b) and (a != b).'
op_result = self.__gt__(other)
if op_result is NotImplemented:
return op_result
return not op_result and self != other
-def _ge_from_gt(self, other):
+def _ge_from_gt(self, other, NotImplemented=NotImplemented):
'Return a >= b. Computed by @total_ordering from (a > b) or (a == b).'
op_result = self.__gt__(other)
return op_result or self == other
-def _le_from_gt(self, other):
+def _le_from_gt(self, other, NotImplemented=NotImplemented):
'Return a <= b. Computed by @total_ordering from (not a > b).'
op_result = self.__gt__(other)
if op_result is NotImplemented:
return op_result
return not op_result
-def _le_from_ge(self, other):
+def _le_from_ge(self, other, NotImplemented=NotImplemented):
'Return a <= b. Computed by @total_ordering from (not a >= b) or (a == b).'
op_result = self.__ge__(other)
if op_result is NotImplemented:
return op_result
return not op_result or self == other
-def _gt_from_ge(self, other):
+def _gt_from_ge(self, other, NotImplemented=NotImplemented):
'Return a > b. Computed by @total_ordering from (a >= b) and (a != b).'
op_result = self.__ge__(other)
if op_result is NotImplemented:
return op_result
return op_result and self != other
-def _lt_from_ge(self, other):
+def _lt_from_ge(self, other, NotImplemented=NotImplemented):
'Return a < b. Computed by @total_ordering from (not a >= b).'
op_result = self.__ge__(other)
if op_result is NotImplemented: