Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Disallow instantiation for the iter type
  • Loading branch information
erlend-aasland committed Jan 19, 2023
commit 2175f66465aa5d480cbf6d7887be94a27cabb548
6 changes: 6 additions & 0 deletions Lib/test/test_xml_etree_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ def test_immutable_types(self):
with self.assertRaisesRegex(TypeError, "immutable"):
tp.foo = 1

@support.cpython_only
def test_disallow_instantiation(self):
root = cET.fromstring('<a></a>')
iter_type = type(root.iter())
support.check_disallow_instantiation(self, iter_type)


@unittest.skipUnless(cET, 'requires _elementtree')
class TestAliasWorking(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ static PyType_Spec elementiter_spec = {
.name = "_elementtree._element_iterator",
.basicsize = sizeof(ElementIterObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
.slots = elementiter_slots,
};

Expand Down