From 7c66906802cd8534b05264bd47acf9eb9db6d09e Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Wed, 3 Jul 2024 10:03:56 -0500 Subject: [PATCH] gh-121300: Add `replace` to `copy.__all__` (#121302) --- Lib/copy.py | 7 ++++--- Lib/test/test_copy.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/copy.py b/Lib/copy.py index 7a1907d7549..a79976d3a65 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -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. diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index 89102373759..3dec64cc9a2 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -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