]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-121300: Add `replace` to `copy.__all__` (GH-121302) (#121337)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 3 Jul 2024 15:28:57 +0000 (17:28 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 15:28:57 +0000 (15:28 +0000)
(cherry picked from commit 7c66906802cd8534b05264bd47acf9eb9db6d09e)

Co-authored-by: Max Muoto <maxmuoto@gmail.com>
Lib/copy.py
Lib/test/test_copy.py

index a69bc4e78c20b308386fa896b6056997cfebdec9..2a4606246aa911218bf797047eef00247791108e 100644 (file)
@@ -4,8 +4,9 @@ Interface summary:
 
         import copy
 
-        x = copy.copy(y)        # make a shallow copy of y
-        x = copy.deepcopy(y)    # make a deep copy of y
+        x = copy.copy(y)                # make a shallow copy of y
+        x = copy.deepcopy(y)            # make a deep copy of y
+        x = copy.replace(y, a=1, b=2)   # new object with fields replaced, as defined by `__replace__`
 
 For module specific errors, copy.Error is raised.
 
@@ -56,7 +57,7 @@ class Error(Exception):
     pass
 error = Error   # backward compatibility
 
-__all__ = ["Error", "copy", "deepcopy"]
+__all__ = ["Error", "copy", "deepcopy", "replace"]
 
 def copy(x):
     """Shallow copy operation on arbitrary Python objects.
index 89102373759ca0ed97831d7e74bcc09c984a9747..3dec64cc9a24141d606fe9a0c0e1b9b7f63ed807 100644 (file)
@@ -972,6 +972,10 @@ class TestReplace(unittest.TestCase):
             copy.replace(c, x=1, error=2)
 
 
+class MiscTestCase(unittest.TestCase):
+    def test__all__(self):
+        support.check__all__(self, copy, not_exported={"dispatch_table", "error"})
+
 def global_foo(x, y): return x+y