Skip to content

Commit 3b97d1b

Browse files
bpo-36543: Revert "bpo-36543: Remove the xml.etree.cElementTree module." (GH-20117) (GH-20780)
* Revert "bpo-36543: Remove the xml.etree.cElementTree module. (GH-19108)" This reverts commit b33e525. (cherry picked from commit ec88e1b)
1 parent d55ed7b commit 3b97d1b

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

Doc/library/xml.etree.elementtree.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ for parsing and creating XML data.
1515

1616
.. versionchanged:: 3.3
1717
This module will use a fast implementation whenever available.
18+
19+
.. deprecated:: 3.3
1820
The :mod:`xml.etree.cElementTree` module is deprecated.
1921

2022

Doc/whatsnew/3.9.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,6 @@ Removed
826826
module have been removed. They were deprecated in Python 3.2.
827827
Use ``iter(x)`` or ``list(x)`` instead of ``x.getchildren()`` and
828828
``x.iter()`` or ``list(x.iter())`` instead of ``x.getiterator()``.
829-
The ``xml.etree.cElementTree`` module has been removed,
830-
use the :mod:`xml.etree.ElementTree` module instead.
831-
Since Python 3.3 the ``xml.etree.cElementTree`` module has been deprecated,
832-
the ``xml.etree.ElementTree`` module uses a fast implementation whenever
833-
available.
834829
(Contributed by Serhiy Storchaka in :issue:`36543`.)
835830

836831
* The old :mod:`plistlib` API has been removed, it was deprecated since Python

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 *
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restored the deprecated :mod:`xml.etree.cElementTree` module.

0 commit comments

Comments
 (0)