[pypy-commit] pypy py3.6: (ronan, mwjackson) added kwargs-only for sorted()

mwjackson pypy.commits at gmail.com
Sat Apr 21 10:20:59 EDT 2018


Author: Matt Jackson <email at mwjackson.net>
Branch: py3.6
Changeset: r94406:5781b52fc50f
Date: 2018-04-21 14:20 +0100
http://bitbucket.org/pypy/pypy/changeset/5781b52fc50f/

Log:	(ronan, mwjackson) added kwargs-only for sorted()

diff --git a/lib-python/3/test/test_builtin.py b/lib-python/3/test/test_builtin.py
--- a/lib-python/3/test/test_builtin.py
+++ b/lib-python/3/test/test_builtin.py
@@ -1635,8 +1635,12 @@
     def test_bad_arguments(self):
         # Issue #29327: The first argument is positional-only.
         sorted([])
-        with self.assertRaises(TypeError):
-            sorted(iterable=[])
+
+        # pypy doesn't support positional only arguments
+        if check_impl_detail():
+            with self.assertRaises(TypeError):
+                sorted(iterable=[])
+
         # Other arguments are keyword-only
         sorted([], key=None)
         with self.assertRaises(TypeError):
diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py
--- a/pypy/module/__builtin__/app_functional.py
+++ b/pypy/module/__builtin__/app_functional.py
@@ -4,8 +4,7 @@
 """
 
 # ____________________________________________________________
-
-def sorted(iterable, key=None, reverse=False):
+def sorted(iterable, *, key=None, reverse=False):
     "sorted(iterable, key=None, reverse=False) --> new sorted list"
     sorted_lst = list(iterable)
     sorted_lst.sort(key=key, reverse=reverse)
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -420,6 +420,7 @@
         assert sorted_l is not l
         assert sorted_l == ['C', 'b', 'a']
         raises(TypeError, sorted, [], reverse=None)
+        raises(TypeError, sorted, [], None)
 
     def test_reversed_simple_sequences(self):
         l = range(5)


More information about the pypy-commit mailing list