Skip to content

Commit d64c2da

Browse files
Revert "bpo-36543: Remove the xml.etree.cElementTree module. (GH-19108)"
This reverts commit b33e525.
1 parent f01d1be commit d64c2da

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Lib/test/test_xml_etree_c.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
cET = import_fresh_module('xml.etree.ElementTree',
1010
fresh=['_elementtree'])
11+
cET_alias = import_fresh_module('xml.etree.cElementTree',
12+
fresh=['_elementtree', 'xml.etree'],
13+
deprecated=True)
1114

1215

1316
@unittest.skipUnless(cET, 'requires _elementtree')
@@ -167,6 +170,14 @@ def test_xmlpullparser_leaks(self):
167170
support.gc_collect()
168171

169172

173+
@unittest.skipUnless(cET, 'requires _elementtree')
174+
class TestAliasWorking(unittest.TestCase):
175+
# Test that the cET alias module is alive
176+
def test_alias_working(self):
177+
e = cET_alias.Element('foo')
178+
self.assertEqual(e.tag, 'foo')
179+
180+
170181
@unittest.skipUnless(cET, 'requires _elementtree')
171182
@support.cpython_only
172183
class TestAcceleratorImported(unittest.TestCase):
@@ -175,6 +186,9 @@ def test_correct_import_cET(self):
175186
# SubElement is a function so it retains _elementtree as its module.
176187
self.assertEqual(cET.SubElement.__module__, '_elementtree')
177188

189+
def test_correct_import_cET_alias(self):
190+
self.assertEqual(cET_alias.SubElement.__module__, '_elementtree')
191+
178192
def test_parser_comes_from_C(self):
179193
# The type of methods defined in Python code is types.FunctionType,
180194
# while the type of methods defined inside _elementtree is
@@ -214,6 +228,7 @@ def test_main():
214228
# Run the tests specific to the C implementation
215229
support.run_unittest(
216230
MiscTests,
231+
TestAliasWorking,
217232
TestAcceleratorImported,
218233
SizeofTest,
219234
)

Lib/xml/etree/cElementTree.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Deprecated alias for xml.etree.ElementTree
2+
3+
from xml.etree.ElementTree import *

0 commit comments

Comments
 (0)