bpo-29204: Emit warnings for already deprecated ElementTree features. (#773)
Element.getiterator() and the html parameter of XMLParser() were
deprecated only in the documentation (since Python 3.2 and 3.4 correspondintly).
Now using them emits a deprecation warning.
* Don’t need check_warnings any more.
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 36aa391..4e1750f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1366,7 +1366,12 @@
Py_ssize_t i;
PyObject* list;
- /* FIXME: report as deprecated? */
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "This method will be removed in future versions. "
+ "Use 'list(elem)' or iteration over elem instead.",
+ 1) < 0) {
+ return NULL;
+ }
if (!self->extra)
return PyList_New(0);
@@ -1416,6 +1421,28 @@
/*[clinic input]
+_elementtree.Element.getiterator
+
+ tag: object = None
+
+[clinic start generated code]*/
+
+static PyObject *
+_elementtree_Element_getiterator_impl(ElementObject *self, PyObject *tag)
+/*[clinic end generated code: output=cb69ff4a3742dfa1 input=500da1a03f7b9e28]*/
+{
+ /* Change for a DeprecationWarning in 1.4 */
+ if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
+ "This method will be removed in future versions. "
+ "Use 'tree.iter()' or 'list(tree.iter())' instead.",
+ 1) < 0) {
+ return NULL;
+ }
+ return _elementtree_Element_iter_impl(self, tag);
+}
+
+
+/*[clinic input]
_elementtree.Element.itertext
[clinic start generated code]*/
@@ -3244,6 +3271,14 @@
PyObject *target, const char *encoding)
/*[clinic end generated code: output=d6a16c63dda54441 input=155bc5695baafffd]*/
{
+ if (html != NULL) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "The html argument of XMLParser() is deprecated",
+ 1) < 0) {
+ return -1;
+ }
+ }
+
self->entity = PyDict_New();
if (!self->entity)
return -1;
@@ -3716,7 +3751,7 @@
_ELEMENTTREE_ELEMENT_ITERTEXT_METHODDEF
_ELEMENTTREE_ELEMENT_ITERFIND_METHODDEF
- {"getiterator", (PyCFunction)_elementtree_Element_iter, METH_FASTCALL, _elementtree_Element_iter__doc__},
+ _ELEMENTTREE_ELEMENT_GETITERATOR_METHODDEF
_ELEMENTTREE_ELEMENT_GETCHILDREN_METHODDEF
_ELEMENTTREE_ELEMENT_ITEMS_METHODDEF
diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h
index c13cb35..7d1fd18 100644
--- a/Modules/clinic/_elementtree.c.h
+++ b/Modules/clinic/_elementtree.c.h
@@ -333,6 +333,35 @@
return return_value;
}
+PyDoc_STRVAR(_elementtree_Element_getiterator__doc__,
+"getiterator($self, /, tag=None)\n"
+"--\n"
+"\n");
+
+#define _ELEMENTTREE_ELEMENT_GETITERATOR_METHODDEF \
+ {"getiterator", (PyCFunction)_elementtree_Element_getiterator, METH_FASTCALL, _elementtree_Element_getiterator__doc__},
+
+static PyObject *
+_elementtree_Element_getiterator_impl(ElementObject *self, PyObject *tag);
+
+static PyObject *
+_elementtree_Element_getiterator(ElementObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"tag", NULL};
+ static _PyArg_Parser _parser = {"|O:getiterator", _keywords, 0};
+ PyObject *tag = Py_None;
+
+ if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
+ &tag)) {
+ goto exit;
+ }
+ return_value = _elementtree_Element_getiterator_impl(self, tag);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(_elementtree_Element_itertext__doc__,
"itertext($self, /)\n"
"--\n"
@@ -726,4 +755,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=b69fa98c40917f58 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=fbc92d64735adec0 input=a9049054013a1b77]*/