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 b33e52511a.
This commit is contained in:
Serhiy Storchaka 2020-06-10 18:39:12 +03:00 committed by GitHub
parent c6483c9896
commit ec88e1bca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 5 deletions

View File

@ -15,6 +15,8 @@ for parsing and creating XML data.
.. versionchanged:: 3.3 .. versionchanged:: 3.3
This module will use a fast implementation whenever available. This module will use a fast implementation whenever available.
.. deprecated:: 3.3
The :mod:`xml.etree.cElementTree` module is deprecated. The :mod:`xml.etree.cElementTree` module is deprecated.

View File

@ -826,11 +826,6 @@ Removed
module have been removed. They were deprecated in Python 3.2. module have been removed. They were deprecated in Python 3.2.
Use ``iter(x)`` or ``list(x)`` instead of ``x.getchildren()`` and Use ``iter(x)`` or ``list(x)`` instead of ``x.getchildren()`` and
``x.iter()`` or ``list(x.iter())`` instead of ``x.getiterator()``. ``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`.) (Contributed by Serhiy Storchaka in :issue:`36543`.)
* The old :mod:`plistlib` API has been removed, it was deprecated since Python * The old :mod:`plistlib` API has been removed, it was deprecated since Python

View File

@ -8,6 +8,9 @@ import unittest
cET = import_fresh_module('xml.etree.ElementTree', cET = import_fresh_module('xml.etree.ElementTree',
fresh=['_elementtree']) fresh=['_elementtree'])
cET_alias = import_fresh_module('xml.etree.cElementTree',
fresh=['_elementtree', 'xml.etree'],
deprecated=True)
@unittest.skipUnless(cET, 'requires _elementtree') @unittest.skipUnless(cET, 'requires _elementtree')
@ -167,6 +170,14 @@ class MiscTests(unittest.TestCase):
support.gc_collect() 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') @unittest.skipUnless(cET, 'requires _elementtree')
@support.cpython_only @support.cpython_only
class TestAcceleratorImported(unittest.TestCase): class TestAcceleratorImported(unittest.TestCase):
@ -175,6 +186,9 @@ class TestAcceleratorImported(unittest.TestCase):
# SubElement is a function so it retains _elementtree as its module. # SubElement is a function so it retains _elementtree as its module.
self.assertEqual(cET.SubElement.__module__, '_elementtree') 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): def test_parser_comes_from_C(self):
# The type of methods defined in Python code is types.FunctionType, # The type of methods defined in Python code is types.FunctionType,
# while the type of methods defined inside _elementtree is # while the type of methods defined inside _elementtree is
@ -214,6 +228,7 @@ def test_main():
# Run the tests specific to the C implementation # Run the tests specific to the C implementation
support.run_unittest( support.run_unittest(
MiscTests, MiscTests,
TestAliasWorking,
TestAcceleratorImported, TestAcceleratorImported,
SizeofTest, SizeofTest,
) )

View File

@ -0,0 +1,3 @@
# Deprecated alias for xml.etree.ElementTree
from xml.etree.ElementTree import *

View File

@ -0,0 +1 @@
Restored the deprecated :mod:`xml.etree.cElementTree` module.