mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-29695: Deprecated using bad named keyword arguments in builtings: (#486)
int(), bool(), float(), list() and tuple(). Specify the value as a positional argument instead.
This commit is contained in:
		
							parent
							
								
									d31b28e16a
								
							
						
					
					
						commit
						58d23e6806
					
				
					 12 changed files with 65 additions and 2 deletions
				
			
		|  | @ -169,6 +169,11 @@ Deprecated | ||||||
|   both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed |   both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed | ||||||
|   by Matthias Bussonnier in :issue:`29576`) |   by Matthias Bussonnier in :issue:`29576`) | ||||||
| 
 | 
 | ||||||
|  | - Using *x* as a keyword argument in :func:`int`, :func:`bool` and | ||||||
|  |   :func:`float` and using *sequence* as a keyword argument in :func:`list` | ||||||
|  |   and :func:`tuple` are deprecated.  Specify the value as a positional argument | ||||||
|  |   instead.  (Contributed by Serhiy Storchaka in :issue:`29695`.) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| Removed | Removed | ||||||
| ======= | ======= | ||||||
|  |  | ||||||
|  | @ -170,6 +170,10 @@ def test_convert(self): | ||||||
|         self.assertIs(bool(""), False) |         self.assertIs(bool(""), False) | ||||||
|         self.assertIs(bool(), False) |         self.assertIs(bool(), False) | ||||||
| 
 | 
 | ||||||
|  |     def test_keyword_args(self): | ||||||
|  |         with self.assertWarns(DeprecationWarning): | ||||||
|  |             self.assertIs(bool(x=10), True) | ||||||
|  | 
 | ||||||
|     def test_format(self): |     def test_format(self): | ||||||
|         self.assertEqual("%d" % False, "0") |         self.assertEqual("%d" % False, "0") | ||||||
|         self.assertEqual("%d" % True, "1") |         self.assertEqual("%d" % True, "1") | ||||||
|  |  | ||||||
|  | @ -208,6 +208,10 @@ def __float__(self): | ||||||
|         with self.assertWarns(DeprecationWarning): |         with self.assertWarns(DeprecationWarning): | ||||||
|             self.assertIs(type(FloatSubclass(F())), FloatSubclass) |             self.assertIs(type(FloatSubclass(F())), FloatSubclass) | ||||||
| 
 | 
 | ||||||
|  |     def test_keyword_args(self): | ||||||
|  |         with self.assertWarns(DeprecationWarning): | ||||||
|  |             self.assertEqual(float(x='3.14'), 3.14) | ||||||
|  | 
 | ||||||
|     def test_is_integer(self): |     def test_is_integer(self): | ||||||
|         self.assertFalse((1.1).is_integer()) |         self.assertFalse((1.1).is_integer()) | ||||||
|         self.assertTrue((1.).is_integer()) |         self.assertTrue((1.).is_integer()) | ||||||
|  |  | ||||||
|  | @ -246,8 +246,10 @@ def test_no_args(self): | ||||||
| 
 | 
 | ||||||
|     def test_keyword_args(self): |     def test_keyword_args(self): | ||||||
|         # Test invoking int() using keyword arguments. |         # Test invoking int() using keyword arguments. | ||||||
|  |         with self.assertWarns(DeprecationWarning): | ||||||
|             self.assertEqual(int(x=1.2), 1) |             self.assertEqual(int(x=1.2), 1) | ||||||
|         self.assertEqual(int('100', base=2), 4) |         self.assertEqual(int('100', base=2), 4) | ||||||
|  |         with self.assertWarns(DeprecationWarning): | ||||||
|             self.assertEqual(int(x='100', base=2), 4) |             self.assertEqual(int(x='100', base=2), 4) | ||||||
|         self.assertRaises(TypeError, int, base=10) |         self.assertRaises(TypeError, int, base=10) | ||||||
|         self.assertRaises(TypeError, int, base=0) |         self.assertRaises(TypeError, int, base=0) | ||||||
|  |  | ||||||
|  | @ -16,6 +16,8 @@ def test_basic(self): | ||||||
|         self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) |         self.assertEqual(list((0, 1, 2, 3)), [0, 1, 2, 3]) | ||||||
|         self.assertEqual(list(''), []) |         self.assertEqual(list(''), []) | ||||||
|         self.assertEqual(list('spam'), ['s', 'p', 'a', 'm']) |         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: |         if sys.maxsize == 0x7fffffff: | ||||||
|             # This test can currently only work on 32-bit machines. |             # This test can currently only work on 32-bit machines. | ||||||
|  | @ -39,6 +41,11 @@ def test_basic(self): | ||||||
|         x.extend(-y for y in x) |         x.extend(-y for y in x) | ||||||
|         self.assertEqual(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): |     def test_truth(self): | ||||||
|         super().test_truth() |         super().test_truth() | ||||||
|         self.assertTrue(not []) |         self.assertTrue(not []) | ||||||
|  |  | ||||||
|  | @ -23,6 +23,13 @@ def test_constructors(self): | ||||||
|         self.assertEqual(tuple([0, 1, 2, 3]), (0, 1, 2, 3)) |         self.assertEqual(tuple([0, 1, 2, 3]), (0, 1, 2, 3)) | ||||||
|         self.assertEqual(tuple(''), ()) |         self.assertEqual(tuple(''), ()) | ||||||
|         self.assertEqual(tuple('spam'), ('s', 'p', 'a', 'm')) |         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): |     def test_truth(self): | ||||||
|         super().test_truth() |         super().test_truth() | ||||||
|  |  | ||||||
|  | @ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1? | ||||||
| Core and Builtins | Core and Builtins | ||||||
| ----------------- | ----------------- | ||||||
| 
 | 
 | ||||||
|  | - bpo-29695: Using "x" as a keyword argument in int(), bool() and float() and | ||||||
|  |   using "sequence" as a keyword argument in list() and tuple() are deprecated. | ||||||
|  |   Specify the value as a positional argument instead. | ||||||
|  | 
 | ||||||
| - bpo-28893: Set correct __cause__ for errors about invalid awaitables | - bpo-28893: Set correct __cause__ for errors about invalid awaitables | ||||||
|   returned from __aiter__ and __anext__. |   returned from __aiter__ and __anext__. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -48,6 +48,12 @@ bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||||||
| 
 | 
 | ||||||
|     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x)) |     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:bool", kwlist, &x)) | ||||||
|         return NULL; |         return NULL; | ||||||
|  |     if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) { | ||||||
|  |         if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  |                 "Using 'x' as a keyword argument is deprecated; " | ||||||
|  |                 "specify the value as a positional argument instead") < 0) | ||||||
|  |             return NULL; | ||||||
|  |     } | ||||||
|     ok = PyObject_IsTrue(x); |     ok = PyObject_IsTrue(x); | ||||||
|     if (ok < 0) |     if (ok < 0) | ||||||
|         return NULL; |         return NULL; | ||||||
|  |  | ||||||
|  | @ -1569,6 +1569,12 @@ float_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||||||
|         return float_subtype_new(type, args, kwds); /* Wimp out */ |         return float_subtype_new(type, args, kwds); /* Wimp out */ | ||||||
|     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) |     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) | ||||||
|         return NULL; |         return NULL; | ||||||
|  |     if (kwds != NULL && PyDict_GET_SIZE(kwds) != 0) { | ||||||
|  |         if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  |                 "Using 'x' as a keyword argument is deprecated; " | ||||||
|  |                 "specify the value as a positional argument instead") < 0) | ||||||
|  |             return NULL; | ||||||
|  |     } | ||||||
|     /* If it's a string, but not a string subclass, use
 |     /* If it's a string, but not a string subclass, use
 | ||||||
|        PyFloat_FromString. */ |        PyFloat_FromString. */ | ||||||
|     if (PyUnicode_CheckExact(x)) |     if (PyUnicode_CheckExact(x)) | ||||||
|  |  | ||||||
|  | @ -2297,6 +2297,12 @@ list_init(PyListObject *self, PyObject *args, PyObject *kw) | ||||||
| 
 | 
 | ||||||
|     if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg)) |     if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:list", kwlist, &arg)) | ||||||
|         return -1; |         return -1; | ||||||
|  |     if (arg != NULL && PyTuple_GET_SIZE(args) == 0) { | ||||||
|  |         if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  |                 "Using 'sequence' as a keyword argument is deprecated; " | ||||||
|  |                 "specify the value as a positional argument instead") < 0) | ||||||
|  |             return -1; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     /* Verify list invariants established by PyType_GenericAlloc() */ |     /* Verify list invariants established by PyType_GenericAlloc() */ | ||||||
|     assert(0 <= Py_SIZE(self)); |     assert(0 <= Py_SIZE(self)); | ||||||
|  |  | ||||||
|  | @ -4811,6 +4811,12 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||||||
|         } |         } | ||||||
|         return PyLong_FromLong(0L); |         return PyLong_FromLong(0L); | ||||||
|     } |     } | ||||||
|  |     if (PyTuple_GET_SIZE(args) == 0) { | ||||||
|  |         if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  |                 "Using 'x' as a keyword argument is deprecated; " | ||||||
|  |                 "specify the value as a positional argument instead") < 0) | ||||||
|  |             return NULL; | ||||||
|  |     } | ||||||
|     if (obase == NULL) |     if (obase == NULL) | ||||||
|         return PyNumber_Long(x); |         return PyNumber_Long(x); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -654,6 +654,12 @@ tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||||||
|         return tuple_subtype_new(type, args, kwds); |         return tuple_subtype_new(type, args, kwds); | ||||||
|     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg)) |     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg)) | ||||||
|         return NULL; |         return NULL; | ||||||
|  |     if (arg != NULL && PyTuple_GET_SIZE(args) == 0) { | ||||||
|  |         if (PyErr_Warn(PyExc_DeprecationWarning, | ||||||
|  |                 "Using 'sequence' as a keyword argument is deprecated; " | ||||||
|  |                 "specify the value as a positional argument instead") < 0) | ||||||
|  |             return NULL; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (arg == NULL) |     if (arg == NULL) | ||||||
|         return PyTuple_New(0); |         return PyTuple_New(0); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka