From 2d920fe666598f28f6fa22798bf9117ccde065f0 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 5 May 2020 13:43:41 +0200 Subject: [PATCH 1/2] bpo-36543: Revert removal xml.etree.cElementTree This reverts commit b33e52511a59c6da7132c226b7f7489b092a33eb. --- Lib/test/test_xml_etree_c.py | 15 +++++++++++++++ Lib/xml/etree/cElementTree.py | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 Lib/xml/etree/cElementTree.py 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..368e6791895829 --- /dev/null +++ b/Lib/xml/etree/cElementTree.py @@ -0,0 +1,3 @@ +# Deprecated alias for xml.etree.ElementTree + +from xml.etree.ElementTree import * From 99cd4efc9ea9dbc65ca4293336ca50b2b2e7b514 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 5 May 2020 13:51:21 +0200 Subject: [PATCH 2/2] bpo-36543: Mark cElementTree to be removed in 3.10 Signed-off-by: Christian Heimes --- Doc/library/xml.etree.elementtree.rst | 2 ++ Doc/whatsnew/3.9.rst | 4 ++++ Lib/xml/etree/cElementTree.py | 9 +++++++++ .../Library/2020-05-05-13-51-07.bpo-36543.4j7Rn3.rst | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-05-05-13-51-07.bpo-36543.4j7Rn3.rst 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/xml/etree/cElementTree.py b/Lib/xml/etree/cElementTree.py index 368e6791895829..3b75bc14bd6b8b 100644 --- a/Lib/xml/etree/cElementTree.py +++ b/Lib/xml/etree/cElementTree.py @@ -1,3 +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. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy