diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index 658bc3a54f86e5..a6412071483aad 100644 --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -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:: diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index fbad0fba20f4b7..b1adc026f3476d 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -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. + (Contributed by Serhiy Storchaka and Christian Heimes in :issue:`36543`) + .. _LibCST: https://libcst.readthedocs.io/ .. _parso: https://parso.readthedocs.io/ diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 7437e13d0611cc..e26e1714a540bd 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -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') @@ -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): @@ -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 @@ -214,6 +228,7 @@ def test_main(): # Run the tests specific to the C implementation support.run_unittest( MiscTests, + TestAliasWorking, TestAcceleratorImported, SizeofTest, ) diff --git a/Lib/xml/etree/cElementTree.py b/Lib/xml/etree/cElementTree.py new file mode 100644 index 00000000000000..3b75bc14bd6b8b --- /dev/null +++ b/Lib/xml/etree/cElementTree.py @@ -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 +) + +del _warn diff --git a/Misc/NEWS.d/next/Library/2020-05-05-13-51-07.bpo-36543.4j7Rn3.rst b/Misc/NEWS.d/next/Library/2020-05-05-13-51-07.bpo-36543.4j7Rn3.rst new file mode 100644 index 00000000000000..cfc91ca2340512 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-05-13-51-07.bpo-36543.4j7Rn3.rst @@ -0,0 +1,2 @@ +Re-add :mod:`xml.etree.cElementTree`, deprecate it in 3.9, and schedule it +for removal in 3.10.