mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Add -3 warnings that set.copy(), dict.copy(), and defaultdict.copy() will go away in Py3.x
This commit is contained in:
		
							parent
							
								
									2e827bfdfe
								
							
						
					
					
						commit
						17a74c395e
					
				
					 3 changed files with 31 additions and 3 deletions
				
			
		| 
						 | 
					@ -1186,12 +1186,22 @@ defdict_copy(defdictobject *dd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* This calls the object's class.  That only works for subclasses
 | 
						/* This calls the object's class.  That only works for subclasses
 | 
				
			||||||
	   whose class constructor has the same signature.  Subclasses that
 | 
						   whose class constructor has the same signature.  Subclasses that
 | 
				
			||||||
	   define a different constructor signature must override copy().
 | 
						   define a different constructor signature must override __copy__().
 | 
				
			||||||
	*/
 | 
						*/
 | 
				
			||||||
	return PyObject_CallFunctionObjArgs((PyObject*)Py_TYPE(dd),
 | 
						return PyObject_CallFunctionObjArgs((PyObject*)Py_TYPE(dd),
 | 
				
			||||||
					    dd->default_factory, dd, NULL);
 | 
										    dd->default_factory, dd, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					defdict_copy_method(defdictobject *dd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (Py_Py3kWarningFlag &&
 | 
				
			||||||
 | 
						    PyErr_Warn(PyExc_DeprecationWarning, 
 | 
				
			||||||
 | 
							       "defaultdict.copy() not supported in 3.x") < 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						return defdict_copy(dd);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
defdict_reduce(defdictobject *dd)
 | 
					defdict_reduce(defdictobject *dd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -1241,7 +1251,7 @@ defdict_reduce(defdictobject *dd)
 | 
				
			||||||
static PyMethodDef defdict_methods[] = {
 | 
					static PyMethodDef defdict_methods[] = {
 | 
				
			||||||
	{"__missing__", (PyCFunction)defdict_missing, METH_O,
 | 
						{"__missing__", (PyCFunction)defdict_missing, METH_O,
 | 
				
			||||||
	 defdict_missing_doc},
 | 
						 defdict_missing_doc},
 | 
				
			||||||
	{"copy", (PyCFunction)defdict_copy, METH_NOARGS,
 | 
						{"copy", (PyCFunction)defdict_copy_method, METH_NOARGS,
 | 
				
			||||||
	 defdict_copy_doc},
 | 
						 defdict_copy_doc},
 | 
				
			||||||
	{"__copy__", (PyCFunction)defdict_copy, METH_NOARGS,
 | 
						{"__copy__", (PyCFunction)defdict_copy, METH_NOARGS,
 | 
				
			||||||
	 defdict_copy_doc},
 | 
						 defdict_copy_doc},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1528,6 +1528,10 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
dict_copy(register PyDictObject *mp)
 | 
					dict_copy(register PyDictObject *mp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (Py_Py3kWarningFlag &&
 | 
				
			||||||
 | 
						    PyErr_Warn(PyExc_DeprecationWarning, 
 | 
				
			||||||
 | 
							       "dict.copy() not supported in 3.x") < 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
	return PyDict_Copy((PyObject*)mp);
 | 
						return PyDict_Copy((PyObject*)mp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1130,9 +1130,23 @@ set_copy(PySetObject *so)
 | 
				
			||||||
	return make_new_set(Py_TYPE(so), (PyObject *)so);
 | 
						return make_new_set(Py_TYPE(so), (PyObject *)so);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static PyObject *
 | 
				
			||||||
 | 
					set_copy_method(PySetObject *so)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (Py_Py3kWarningFlag &&
 | 
				
			||||||
 | 
						    PyErr_Warn(PyExc_DeprecationWarning, 
 | 
				
			||||||
 | 
							       "set.copy() not supported in 3.x") < 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
						return make_new_set(Py_TYPE(so), (PyObject *)so);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static PyObject *
 | 
					static PyObject *
 | 
				
			||||||
frozenset_copy(PySetObject *so)
 | 
					frozenset_copy(PySetObject *so)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (Py_Py3kWarningFlag &&
 | 
				
			||||||
 | 
						    PyErr_Warn(PyExc_DeprecationWarning, 
 | 
				
			||||||
 | 
							       "frozenset.copy() not supported in 3.x") < 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
	if (PyFrozenSet_CheckExact(so)) {
 | 
						if (PyFrozenSet_CheckExact(so)) {
 | 
				
			||||||
		Py_INCREF(so);
 | 
							Py_INCREF(so);
 | 
				
			||||||
		return (PyObject *)so;
 | 
							return (PyObject *)so;
 | 
				
			||||||
| 
						 | 
					@ -1911,7 +1925,7 @@ static PyMethodDef set_methods[] = {
 | 
				
			||||||
	 clear_doc},
 | 
						 clear_doc},
 | 
				
			||||||
	{"__contains__",(PyCFunction)set_direct_contains,	METH_O | METH_COEXIST,
 | 
						{"__contains__",(PyCFunction)set_direct_contains,	METH_O | METH_COEXIST,
 | 
				
			||||||
	 contains_doc},
 | 
						 contains_doc},
 | 
				
			||||||
	{"copy",	(PyCFunction)set_copy,		METH_NOARGS,
 | 
						{"copy",	(PyCFunction)set_copy_method,	METH_NOARGS,
 | 
				
			||||||
	 copy_doc},
 | 
						 copy_doc},
 | 
				
			||||||
	{"discard",	(PyCFunction)set_discard,	METH_O,
 | 
						{"discard",	(PyCFunction)set_discard,	METH_O,
 | 
				
			||||||
	 discard_doc},
 | 
						 discard_doc},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue