Skip to content

bpo-36543: Restore cElementTree and mark it for removal in 3.10 #19921

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Doc/library/xml.etree.elementtree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ for parsing and creating XML data.
This module will use a fast implementation whenever available.
The :mod:`xml.etree.cElementTree` module is deprecated.

.. versionchanged:: 3.9
The :mod:`xml.etree.cElementTree` will be removed in Python 3.10.

.. warning::

Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ Deprecated
`parso`_.
(Contributed by Carl Meyer in :issue:`40360`.)

* The :mod:`xml.etree.cElementTree` module has been deprecated since Python
3.3 and is scheduled to be removed in Python 3.10.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use more direct wording:

  • clearer
  • similar to that in xml.etree.elementtree.rst
  • fewer words = more readable
Suggested change
3.3 and is scheduled to be removed in Python 3.10.
3.3 and will be removed in Python 3.10.

(Contributed by Serhiy Storchaka and Christian Heimes in :issue:`36543`)

.. _LibCST: https://libcst.readthedocs.io/
.. _parso: https://parso.readthedocs.io/

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
12 changes: 12 additions & 0 deletions Lib/xml/etree/cElementTree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Deprecated alias for xml.etree.ElementTree

from xml.etree.ElementTree import *

from warnings import warn as _warn

_warn(
"xml.etree.cElementTree is deprecated, use xml.etree.ElementTree instead",
PendingDeprecationWarning
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
)
del _warn


del _warn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Re-add :mod:`xml.etree.cElementTree`, deprecate it in 3.9, and schedule it
for removal in 3.10.