Skip to content

Commit 3847a6c

Browse files
pythongh-92123: Convert _elementtree types to heap types (python#99221)
1 parent 9109d46 commit 3847a6c

File tree

4 files changed

+185
-236
lines changed

4 files changed

+185
-236
lines changed

Lib/test/test_xml_etree_c.py

+20
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ def __hash__(self):
181181
r = e.get(X())
182182
self.assertIsNone(r)
183183

184+
@support.cpython_only
185+
def test_immutable_types(self):
186+
root = cET.fromstring('<a></a>')
187+
dataset = (
188+
cET.Element,
189+
cET.TreeBuilder,
190+
cET.XMLParser,
191+
type(root.iter()),
192+
)
193+
for tp in dataset:
194+
with self.subTest(tp=tp):
195+
with self.assertRaisesRegex(TypeError, "immutable"):
196+
tp.foo = 1
197+
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+
184204

185205
@unittest.skipUnless(cET, 'requires _elementtree')
186206
class TestAliasWorking(unittest.TestCase):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Convert :mod:`elementtree` types to heap types. Patch by Erlend E. Aasland.

0 commit comments

Comments
 (0)