Skip to content

Commit 2175f66

Browse files
Disallow instantiation for the iter type
1 parent c8a3c67 commit 2175f66

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/test_xml_etree_c.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ def test_immutable_types(self):
195195
with self.assertRaisesRegex(TypeError, "immutable"):
196196
tp.foo = 1
197197

198+
@support.cpython_only
199+
def test_disallow_instantiation(self):
200+
root = cET.fromstring('<a></a>')
201+
iter_type = type(root.iter())
202+
support.check_disallow_instantiation(self, iter_type)
203+
198204

199205
@unittest.skipUnless(cET, 'requires _elementtree')
200206
class TestAliasWorking(unittest.TestCase):

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ static PyType_Spec elementiter_spec = {
21942194
.name = "_elementtree._element_iterator",
21952195
.basicsize = sizeof(ElementIterObject),
21962196
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
2197-
Py_TPFLAGS_IMMUTABLETYPE),
2197+
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
21982198
.slots = elementiter_slots,
21992199
};
22002200

0 commit comments

Comments
 (0)