Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c7c9af

Browse files
committed
Clean-up functools.total_ordering().
1 parent bb734c6 commit 4c7c9af

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

Lib/functools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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__}
6968
def 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__

Misc/NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)