File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,7 +65,6 @@ def wraps(wrapped,
6565 return partial (update_wrapper , wrapped = wrapped ,
6666 assigned = assigned , updated = updated )
6767
68- _object_defaults = {object .__lt__ , object .__le__ , object .__gt__ , object .__ge__ }
6968def total_ordering (cls ):
7069 """Class decorator that fills in missing ordering methods"""
7170 convert = {
@@ -82,9 +81,8 @@ def total_ordering(cls):
8281 ('__gt__' , lambda self , other : not other >= self ),
8382 ('__lt__' , lambda self , other : not self >= other )]
8483 }
85- roots = set (dir (cls )) & set (convert )
86- # Remove default comparison operations defined on object.
87- roots -= {meth for meth in roots if getattr (cls , meth ) in _object_defaults }
84+ # Find comparisons not inherited from object.
85+ roots = [op for op in convert if getattr (cls , op ) is not getattr (object , op )]
8886 if not roots :
8987 raise ValueError ('must define at least one ordering operation: < > <= >=' )
9088 root = max (roots ) # prefer __lt__ to __le__ to __gt__ to __ge__
Original file line number Diff line number Diff line change @@ -222,7 +222,7 @@ Library
222222
223223- Issue #9501: Fixed logging regressions in cleanup code.
224224
225- - Fix functools.total_ordering() to actually work .
225+ - Fix functools.total_ordering() to skip methods inherited from object() .
226226
227227- Issue #9572: Importlib should not raise an exception if a directory it
228228 thought it needed to create was done concurrently by another process.
You can’t perform that action at this time.
0 commit comments