]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94383: Remove ElementTree.Element.copy() method (#94384)
authorVictor Stinner <vstinner@python.org>
Mon, 4 Jul 2022 13:51:01 +0000 (15:51 +0200)
committerGitHub <noreply@github.com>
Mon, 4 Jul 2022 13:51:01 +0000 (15:51 +0200)
xml.etree: Remove the ElementTree.Element.copy() method of the pure
Python implementation, deprecated in Python 3.10, use the copy.copy()
function instead. The C implementation of xml.etree has no copy()
method, only a __copy__() method.

Doc/whatsnew/3.12.rst
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Misc/NEWS.d/next/Library/2022-06-28-14-41-22.gh-issue-94383.CXnquo.rst [new file with mode: 0644]

index ed21abaeb6dc18da8035d9721c75a81c5ab81ce2..43239a75f701a204373cd13421507e6bbb23894d 100644 (file)
@@ -293,6 +293,12 @@ Removed
   a C implementation of :func:`~hashlib.pbkdf2_hmac()` which is faster.
   (Contributed by Victor Stinner in :gh:`94199`.)
 
+* :mod:`xml.etree`: Remove the ``ElementTree.Element.copy()`` method of the
+  pure Python implementation, deprecated in Python 3.10, use the
+  :func:`copy.copy` function instead.  The C implementation of :mod:`xml.etree`
+  has no ``copy()`` method, only a ``__copy__()`` method.
+  (Contributed by Victor Stinner in :gh:`94383`.)
+
 
 Porting to Python 3.12
 ======================
index afa4641e6906b70d04bb8dc1414fdb70a0e081cd..839955695b800f93426486cc8ffa52e0694c0aa5 100644 (file)
@@ -2333,35 +2333,6 @@ class BasicElementTest(ElementTestCase, unittest.TestCase):
         self.assertIsNot(element_foo.attrib, attrib)
         self.assertNotEqual(element_foo.attrib, attrib)
 
-    def test_copy(self):
-        # Only run this test if Element.copy() is defined.
-        if "copy" not in dir(ET.Element):
-            raise unittest.SkipTest("Element.copy() not present")
-
-        element_foo = ET.Element("foo", { "zix": "wyp" })
-        element_foo.append(ET.Element("bar", { "baz": "qix" }))
-
-        with self.assertWarns(DeprecationWarning):
-            element_foo2 = element_foo.copy()
-
-        # elements are not the same
-        self.assertIsNot(element_foo2, element_foo)
-
-        # string attributes are equal
-        self.assertEqual(element_foo2.tag, element_foo.tag)
-        self.assertEqual(element_foo2.text, element_foo.text)
-        self.assertEqual(element_foo2.tail, element_foo.tail)
-
-        # number of children is the same
-        self.assertEqual(len(element_foo2), len(element_foo))
-
-        # children are the same
-        for (child1, child2) in itertools.zip_longest(element_foo, element_foo2):
-            self.assertIs(child1, child2)
-
-        # attrib is a copy
-        self.assertEqual(element_foo2.attrib, element_foo.attrib)
-
     def test___copy__(self):
         element_foo = ET.Element("foo", { "zix": "wyp" })
         element_foo.append(ET.Element("bar", { "baz": "qix" }))
index 1dc80351bf7dddcea33a750ba809a4c7ef793726..ebbe2b703bfd8fc7d02a85cb2771591708f30461 100644 (file)
@@ -188,19 +188,6 @@ class Element:
         """
         return self.__class__(tag, attrib)
 
-    def copy(self):
-        """Return copy of current element.
-
-        This creates a shallow copy. Subelements will be shared with the
-        original tree.
-
-        """
-        warnings.warn(
-            "elem.copy() is deprecated. Use copy.copy(elem) instead.",
-            DeprecationWarning
-            )
-        return self.__copy__()
-
     def __copy__(self):
         elem = self.makeelement(self.tag, self.attrib)
         elem.text = self.text
diff --git a/Misc/NEWS.d/next/Library/2022-06-28-14-41-22.gh-issue-94383.CXnquo.rst b/Misc/NEWS.d/next/Library/2022-06-28-14-41-22.gh-issue-94383.CXnquo.rst
new file mode 100644 (file)
index 0000000..9ed476b
--- /dev/null
@@ -0,0 +1,5 @@
+:mod:`xml.etree`: Remove the ``ElementTree.Element.copy()`` method of the
+pure Python implementation, deprecated in Python 3.10, use the
+:func:`copy.copy` function instead. The C implementation of :mod:`xml.etree`
+has no ``copy()`` method, only a ``__copy__()`` method. Patch by Victor
+Stinner.