[Python-checkins] Conceptually, roots is a set. Also searching it as a set is a tiny bit faster (#3338)

Raymond Hettinger webhook-mailer at python.org
Tue Sep 5 12:40:47 EDT 2017


https://github.com/python/cpython/commit/15ce0bee973596f02983f39e1a1b172b91e9cdda
commit: 15ce0bee973596f02983f39e1a1b172b91e9cdda
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2017-09-05T09:40:44-07:00
summary:

Conceptually, roots is a set.  Also searching it as a set is a tiny bit faster (#3338)

files:
M Lib/functools.py

diff --git a/Lib/functools.py b/Lib/functools.py
index 0873f207154..23ad1609300 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -193,7 +193,7 @@ def _lt_from_ge(self, other, NotImplemented=NotImplemented):
 def total_ordering(cls):
     """Class decorator that fills in missing ordering methods"""
     # Find user-defined comparisons (not those inherited from object).
-    roots = [op for op in _convert if getattr(cls, op, None) is not getattr(object, op, None)]
+    roots = {op for op in _convert if getattr(cls, op, None) is not getattr(object, op, None)}
     if not roots:
         raise ValueError('must define at least one ordering operation: < > <= >=')
     root = max(roots)       # prefer __lt__ to __le__ to __gt__ to __ge__



More information about the Python-checkins mailing list