diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-30 15:12:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-30 15:12:06 (GMT) |
commit | 762ec97ea68a1126b8855996c61fa8239dc9fff7 (patch) | |
tree | 8addf50d8a5ed50492790532396b08d1d25737bd /Modules | |
parent | 722a3af092b94983aa26f5e591fb1b45e2c2a0ff (diff) | |
download | cpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.zip cpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.tar.gz cpython-762ec97ea68a1126b8855996c61fa8239dc9fff7.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_elementtree.c | 39 | ||||
-rw-r--r-- | Modules/clinic/_elementtree.c.h | 31 |
2 files changed, 67 insertions, 3 deletions
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 @@ _elementtree_Element_getchildren_impl(ElementObject *self) 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 @@ _elementtree_Element_iter_impl(ElementObject *self, PyObject *tag) /*[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 @@ _elementtree_XMLParser___init___impl(XMLParserObject *self, PyObject *html, 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 @@ static PyMethodDef element_methods[] = { _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 @@ exit: 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 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject **args, Py_ssi exit: return return_value; } -/*[clinic end generated code: output=b69fa98c40917f58 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fbc92d64735adec0 input=a9049054013a1b77]*/ |