summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShantanu <hauntsaninja@users.noreply.github.com>2020-03-02 06:33:24 (GMT)
committerGitHub <noreply@github.com>2020-03-02 06:33:24 (GMT)
commit4edc95cf0a2960431621eee9bc194f6225f1690b (patch)
tree797be15086532d032931aa450b9f511dbbdb78b6
parent1f577ce363121d590b51abf5c41d1bcf3d751436 (diff)
downloadcpython-4edc95cf0a2960431621eee9bc194f6225f1690b.zip
cpython-4edc95cf0a2960431621eee9bc194f6225f1690b.tar.gz
cpython-4edc95cf0a2960431621eee9bc194f6225f1690b.tar.bz2
bpo-39495: Remove default value from C impl of TreeBuilder.start (GH-18275)
-rw-r--r--Lib/test/test_xml_etree.py4
-rw-r--r--Misc/NEWS.d/next/Library/2020-01-30-07-02-02.bpo-39495.8LsIRN.rst1
-rw-r--r--Modules/_elementtree.c4
-rw-r--r--Modules/clinic/_elementtree.c.h14
4 files changed, 14 insertions, 9 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 09c234c..785edb7 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -2259,6 +2259,10 @@ class BugsTest(unittest.TestCase):
text = text[6:-4]
self.assertEqual(root.get('b'), text)
+ def test_39495_treebuilder_start(self):
+ self.assertRaises(TypeError, ET.TreeBuilder().start, "tag")
+ self.assertRaises(TypeError, ET.TreeBuilder().start, "tag", None)
+
# --------------------------------------------------------------------
diff --git a/Misc/NEWS.d/next/Library/2020-01-30-07-02-02.bpo-39495.8LsIRN.rst b/Misc/NEWS.d/next/Library/2020-01-30-07-02-02.bpo-39495.8LsIRN.rst
new file mode 100644
index 0000000..116a518
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-01-30-07-02-02.bpo-39495.8LsIRN.rst
@@ -0,0 +1 @@
+Remove default value from *attrs* parameter of :meth:`xml.etree.ElementTree.TreeBuilder.start` for consistency between Python and C implementations.
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 4498c5f..c0f771f 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3038,7 +3038,7 @@ _elementtree_TreeBuilder_close_impl(TreeBuilderObject *self)
_elementtree.TreeBuilder.start
tag: object
- attrs: object = None
+ attrs: object(subclass_of='&PyDict_Type')
/
[clinic start generated code]*/
@@ -3046,7 +3046,7 @@ _elementtree.TreeBuilder.start
static PyObject *
_elementtree_TreeBuilder_start_impl(TreeBuilderObject *self, PyObject *tag,
PyObject *attrs)
-/*[clinic end generated code: output=e7e9dc2861349411 input=95fc1758dd042c65]*/
+/*[clinic end generated code: output=e7e9dc2861349411 input=7288e9e38e63b2b6]*/
{
return treebuilder_handle_start(self, tag, attrs);
}
diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h
index a184b0f..dae5233 100644
--- a/Modules/clinic/_elementtree.c.h
+++ b/Modules/clinic/_elementtree.c.h
@@ -761,7 +761,7 @@ _elementtree_TreeBuilder_close(TreeBuilderObject *self, PyObject *Py_UNUSED(igno
}
PyDoc_STRVAR(_elementtree_TreeBuilder_start__doc__,
-"start($self, tag, attrs=None, /)\n"
+"start($self, tag, attrs, /)\n"
"--\n"
"\n");
@@ -777,17 +777,17 @@ _elementtree_TreeBuilder_start(TreeBuilderObject *self, PyObject *const *args, P
{
PyObject *return_value = NULL;
PyObject *tag;
- PyObject *attrs = Py_None;
+ PyObject *attrs;
- if (!_PyArg_CheckPositional("start", nargs, 1, 2)) {
+ if (!_PyArg_CheckPositional("start", nargs, 2, 2)) {
goto exit;
}
tag = args[0];
- if (nargs < 2) {
- goto skip_optional;
+ if (!PyDict_Check(args[1])) {
+ _PyArg_BadArgument("start", "argument 2", "dict", args[1]);
+ goto exit;
}
attrs = args[1];
-skip_optional:
return_value = _elementtree_TreeBuilder_start_impl(self, tag, attrs);
exit:
@@ -916,4 +916,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=bee26d0735a3fddc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3ad029ba71f5ae39 input=a9049054013a1b77]*/