https://github.com/python/cpython/commit/8799f0537b0b3c87280a3291f0efc5eb8047066a commit: 8799f0537b0b3c87280a3291f0efc5eb8047066a branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2024-07-03T15:28:57Z summary:
[3.13] gh-121300: Add `replace` to `copy.__all__` (GH-121302) (#121337) (cherry picked from commit 7c66906802cd8534b05264bd47acf9eb9db6d09e) Co-authored-by: Max Muoto <[email protected]> files: M Lib/copy.py M Lib/test/test_copy.py diff --git a/Lib/copy.py b/Lib/copy.py index a69bc4e78c20b3..2a4606246aa911 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -4,8 +4,9 @@ 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 89102373759ca0..3dec64cc9a2414 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -972,6 +972,10 @@ class C: 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 _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
