Skip to content

gh-121300: Add replace to copy.__all__ #121302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Lib/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -56,7 +57,7 @@ class Error(Exception):
pass
error = Error # backward compatibility

__all__ = ["Error", "copy", "deepcopy"]
__all__ = ["Error", "copy", "deepcopy", "replace"]
Copy link
Contributor

@pygeek pygeek Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a regression test so this doesn't happen again. See helper method support.test__all__ in the test directory—it automatically detects public methods based on whether they follow the public name convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me go ahead, good callout.


def copy(x):
"""Shallow copy operation on arbitrary Python objects.
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Loading