Skip to content

bpo-36543: Revert "bpo-36543: Remove the xml.etree.cElementTree module." #20117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 changes: 2 additions & 0 deletions Doc/library/xml.etree.elementtree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ for parsing and creating XML data.

.. versionchanged:: 3.3
This module will use a fast implementation whenever available.

.. versiondeprecated:: 3.3
The :mod:`xml.etree.cElementTree` module is deprecated.


Expand Down
5 changes: 0 additions & 5 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,6 @@ Removed
module have been removed. They were deprecated in Python 3.2.
Use ``iter(x)`` or ``list(x)`` instead of ``x.getchildren()`` and
``x.iter()`` or ``list(x.iter())`` instead of ``x.getiterator()``.
The ``xml.etree.cElementTree`` module has been removed,
use the :mod:`xml.etree.ElementTree` module instead.
Since Python 3.3 the ``xml.etree.cElementTree`` module has been deprecated,
the ``xml.etree.ElementTree`` module uses a fast implementation whenever
available.
(Contributed by Serhiy Storchaka in :issue:`36543`.)

* The old :mod:`plistlib` API has been removed, it was deprecated since Python
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_xml_etree_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

cET = import_fresh_module('xml.etree.ElementTree',
fresh=['_elementtree'])
cET_alias = import_fresh_module('xml.etree.cElementTree',
fresh=['_elementtree', 'xml.etree'],
deprecated=True)


@unittest.skipUnless(cET, 'requires _elementtree')
Expand Down Expand Up @@ -167,6 +170,14 @@ def test_xmlpullparser_leaks(self):
support.gc_collect()


@unittest.skipUnless(cET, 'requires _elementtree')
class TestAliasWorking(unittest.TestCase):
# Test that the cET alias module is alive
def test_alias_working(self):
e = cET_alias.Element('foo')
self.assertEqual(e.tag, 'foo')


@unittest.skipUnless(cET, 'requires _elementtree')
@support.cpython_only
class TestAcceleratorImported(unittest.TestCase):
Expand All @@ -175,6 +186,9 @@ def test_correct_import_cET(self):
# SubElement is a function so it retains _elementtree as its module.
self.assertEqual(cET.SubElement.__module__, '_elementtree')

def test_correct_import_cET_alias(self):
self.assertEqual(cET_alias.SubElement.__module__, '_elementtree')

def test_parser_comes_from_C(self):
# The type of methods defined in Python code is types.FunctionType,
# while the type of methods defined inside _elementtree is
Expand Down Expand Up @@ -214,6 +228,7 @@ def test_main():
# Run the tests specific to the C implementation
support.run_unittest(
MiscTests,
TestAliasWorking,
TestAcceleratorImported,
SizeofTest,
)
Expand Down
3 changes: 3 additions & 0 deletions Lib/xml/etree/cElementTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Deprecated alias for xml.etree.ElementTree

from xml.etree.ElementTree import *
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restored the deprecated :mod:`xml.etree.cElementTree` module.