Skip to content

Commit 7c66906

Browse files
authored
gh-121300: Add replace to copy.__all__ (#121302)
1 parent ca2e876 commit 7c66906

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Lib/copy.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
55
import copy
66
7-
x = copy.copy(y) # make a shallow copy of y
8-
x = copy.deepcopy(y) # make a deep copy of y
7+
x = copy.copy(y) # make a shallow copy of y
8+
x = copy.deepcopy(y) # make a deep copy of y
9+
x = copy.replace(y, a=1, b=2) # new object with fields replaced, as defined by `__replace__`
910
1011
For module specific errors, copy.Error is raised.
1112
@@ -56,7 +57,7 @@ class Error(Exception):
5657
pass
5758
error = Error # backward compatibility
5859

59-
__all__ = ["Error", "copy", "deepcopy"]
60+
__all__ = ["Error", "copy", "deepcopy", "replace"]
6061

6162
def copy(x):
6263
"""Shallow copy operation on arbitrary Python objects.

Lib/test/test_copy.py

+4
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,10 @@ class C:
972972
copy.replace(c, x=1, error=2)
973973

974974

975+
class MiscTestCase(unittest.TestCase):
976+
def test__all__(self):
977+
support.check__all__(self, copy, not_exported={"dispatch_table", "error"})
978+
975979
def global_foo(x, y): return x+y
976980

977981

0 commit comments

Comments
 (0)