diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index aee62dc..48c3691 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -16,6 +16,8 @@ class ListTest(list_tests.CommonTest): self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) self.assertEqual(list(''), []) self.assertEqual(list('spam'), ['s', 'p', 'a', 'm']) + self.assertEqual(list(x for x in range(10) if x % 2), + [1, 3, 5, 7, 9]) if sys.maxsize == 0x7fffffff: # This test can currently only work on 32-bit machines. @@ -39,6 +41,11 @@ class ListTest(list_tests.CommonTest): x.extend(-y for y in x) self.assertEqual(x, []) + def test_keyword_args(self): + with self.assertWarns(DeprecationWarning): + self.assertEqual(list(sequence=(x for x in range(10) if x % 2)), + [1, 3, 5, 7, 9]) + def test_truth(self): super().test_truth() self.assertTrue(not []) diff --git a/Lib/test/test_tuple.py b/Lib/test/test_tuple.py index 5d1fcf6..d3663ac 100644 --- a/Lib/test/test_tuple.py +++ b/Lib/test/test_tuple.py @@ -23,6 +23,13 @@ class TupleTest(seq_tests.CommonTest): self.assertEqual(tuple([0, 1, 2, 3]), (0, 1, 2, 3)) self.assertEqual(tuple(''), ()) self.assertEqual(tuple('spam'), ('s', 'p', 'a', 'm')) + self.assertEqual(tuple(x for x in range(10) if x % 2), + (1, 3, 5, 7, 9)) + + def test_keyword_args(self): + with self.assertWarns(DeprecationWarning): + self.assertEqual(tuple(sequence=(x for x in range(10) if x % 2)), + (1, 3, 5, 7, 9)) def test_truth(self): super().test_truth() diff --git a/Objects/listobject.c b/Objects/listobject.c index edd4a15..e8c9c43 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2297,6 +2297,11 @@ list_init(PyListObject *self, PyObject *args, PyObject *kw) if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg)) return -1; + if (arg != NULL && PyTuple_GET_SIZE(args) == 0) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "The \"sequence\" keyword argument of list() is deprecated") < 0) + return -1; + } /* Verify list invariants established by PyType_GenericAlloc() */ assert(0 <= Py_SIZE(self)); diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 5bcadeb..d1a5b0a 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -654,6 +654,11 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return tuple_subtype_new(type, args, kwds); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg)) return NULL; + if (arg != NULL && PyTuple_GET_SIZE(args) == 0) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "The \"sequence\" keyword argument of tuple() is deprecated") < 0) + return NULL; + } if (arg == NULL) return PyTuple_New(0);