diff --git a/Lib/copy.py b/Lib/copy.py index 6e8c19bc652d12..4390ed0e21afb8 100644 --- a/Lib/copy.py +++ b/Lib/copy.py @@ -185,6 +185,7 @@ def _deepcopy_atomic(x, memo): d[types.CodeType] = _deepcopy_atomic d[type] = _deepcopy_atomic d[range] = _deepcopy_atomic +d[slice] = _deepcopy_atomic d[types.BuiltinFunctionType] = _deepcopy_atomic d[types.FunctionType] = _deepcopy_atomic d[weakref.ref] = _deepcopy_atomic diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index cc95a319d35d78..98f122c20f46c0 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -354,7 +354,7 @@ def f(): pass tests = [None, 42, 2**100, 3.14, True, False, 1j, "hello", "hello\u1234", f.__code__, - NewStyle, range(10), max, property()] + NewStyle, range(10), max, property(), slice(1, 10, 1)] for x in tests: self.assertIs(copy.deepcopy(x), x) diff --git a/Misc/NEWS.d/next/Library/2023-01-07-12-38-22.gh-issue-100817.7iMrim.rst b/Misc/NEWS.d/next/Library/2023-01-07-12-38-22.gh-issue-100817.7iMrim.rst new file mode 100644 index 00000000000000..8c03d996c12fb3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-01-07-12-38-22.gh-issue-100817.7iMrim.rst @@ -0,0 +1 @@ +Speed up ``copy.deepcopy`` calls on ``slice`` instances.