[Python-checkins] bpo-36543: Revert "bpo-36543: Remove the xml.etree.cElementTree module." (GH-20117)

Serhiy Storchaka webhook-mailer at python.org
Wed Jun 10 11:39:20 EDT 2020


https://github.com/python/cpython/commit/ec88e1bca81a167e6d5c0ac635e22f84298cb1df
commit: ec88e1bca81a167e6d5c0ac635e22f84298cb1df
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020年06月10日T17:39:12+02:00
summary:
bpo-36543: Revert "bpo-36543: Remove the xml.etree.cElementTree module." (GH-20117)
* Revert "bpo-36543: Remove the xml.etree.cElementTree module. (GH-19108)"
This reverts commit b33e52511a59c6da7132c226b7f7489b092a33eb.
files:
A Lib/xml/etree/cElementTree.py
A Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst
M Doc/library/xml.etree.elementtree.rst
M Doc/whatsnew/3.9.rst
M Lib/test/test_xml_etree_c.py
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst
index 2085a85927e46..7725e4d158d42 100644
--- a/Doc/library/xml.etree.elementtree.rst
+++ b/Doc/library/xml.etree.elementtree.rst
@@ -15,6 +15,8 @@ for parsing and creating XML data.
 
 .. versionchanged:: 3.3
 This module will use a fast implementation whenever available.
+
+.. deprecated:: 3.3
 The :mod:`xml.etree.cElementTree` module is deprecated.
 
 
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index b20cd14565ae1..67a83bc958457 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -826,11 +826,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
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
index 7437e13d0611c..e26e1714a540b 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()
 
 
+ at 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 0000000000000..368e679189582
--- /dev/null
+++ b/Lib/xml/etree/cElementTree.py
@@ -0,0 +1,3 @@
+# Deprecated alias for xml.etree.ElementTree
+
+from xml.etree.ElementTree import *
diff --git a/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst b/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst
new file mode 100644
index 0000000000000..468c1ac9eee17
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-05-15-21-14-45.bpo-36543.Jt-eSX.rst
@@ -0,0 +1 @@
+Restored the deprecated :mod:`xml.etree.cElementTree` module.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /