Mike Bayer avatar Mike Bayer committed f00fb24

- recall that groupby() expects a sorted collection, ditch it

Comments (0)

Files changed (1)


 def _sort_states(states):
-    ret = []
-    for haskey, g in groupby(states, key=lambda s:s.key is not None):
-        if haskey:
-            ret.extend(sorted(g, key=lambda st: st.key[1]))
-        else:
-            ret = sorted(g, key=operator.attrgetter("insert_order")) + ret
-    return ret
+    pending = set(states)
+    persistent = set(s for s in pending if s.key is not None)
+    pending.difference_update(persistent)
+    return sorted(pending, key=operator.attrgetter("insert_order")) + \
+        sorted(persistent, key=lambda q:q.key[1])
 class _ColumnMapping(util.py25_dict):
     """Error reporting helper for mapper._columntoproperty."""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.