Commit 5c56bc7b authored by Arnaud Fontaine's avatar Arnaud Fontaine

py3: {sorted,sort}() `cmp` argument has been removed.

parent c9479eaf
...@@ -200,10 +200,14 @@ def get_iteritems(c, name): ...@@ -200,10 +200,14 @@ def get_iteritems(c, name):
_dict_white_list['iteritems'] = get_iteritems _dict_white_list['iteritems'] = get_iteritems
def guarded_sorted(seq, cmp=None, key=None, reverse=False): def guarded_sorted(seq, cmp=None, key=None, reverse=False):
if cmp is not None:
from functools import cmp_to_key
key = cmp_to_key(cmp)
if not isinstance(seq, SafeIter): if not isinstance(seq, SafeIter):
for i, x in enumerate(seq): for i, x in enumerate(seq):
guard(seq, x, i) guard(seq, x, i)
return sorted(seq, cmp=cmp, key=key, reverse=reverse) return sorted(seq, key=key, reverse=reverse)
safe_builtins['sorted'] = guarded_sorted safe_builtins['sorted'] = guarded_sorted
def guarded_reversed(seq): def guarded_reversed(seq):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment