From 55347f4fe1552ea36b22c000fba35967f45e5025 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 30 May 2026 23:57:07 +0300 Subject: [PATCH 1/3] gh-150636: Clarify difference between copy.copy() and the copy() methods --- Doc/library/copy.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index 121c44a16ad43b..e4301ab9b77948 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -72,9 +72,13 @@ file, socket, window, or any similar types. It does "copy" functions and classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the :mod:`pickle` module. -Shallow copies of dictionaries can be made using :meth:`dict.copy`, and -of lists by assigning a slice of the entire list, for example, -``copied_list = original_list[:]``. +Shallow copies of many collections can be made using the corresponding +:meth:`!copy` method (such as :meth:`list.copy`, :meth:`dict.copy`, +:meth:`set.copy`), and of sequences (lists, bytearrays, etc) by making a slice +of the entire sequence, for example, ``alist[:]``. +But such methods can create an instance of the base type when copying +an instance of a subclass, whereas :func:`copy.copy` normally returns +an instance of the same type. .. index:: pair: module; pickle From 375d4d0a3832668313d8238f32aecf47154891c8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 31 May 2026 10:30:31 +0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Pieter Eendebak --- Doc/library/copy.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index e4301ab9b77948..3f9136c354649e 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -73,8 +73,8 @@ classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the :mod:`pickle` module. Shallow copies of many collections can be made using the corresponding -:meth:`!copy` method (such as :meth:`list.copy`, :meth:`dict.copy`, -:meth:`set.copy`), and of sequences (lists, bytearrays, etc) by making a slice +:meth:`!copy` method (such as :meth:`list.copy`, :meth:`dict.copy` or +:meth:`set.copy`), and of sequences (lists, bytearrays, etc.) by making a slice of the entire sequence, for example, ``alist[:]``. But such methods can create an instance of the base type when copying an instance of a subclass, whereas :func:`copy.copy` normally returns From 0dae5d32f3f89ca5eb2f88b3246d3bfda8a94b82 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 31 May 2026 14:36:36 +0300 Subject: [PATCH 3/3] Address review comments. --- Doc/library/copy.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index 3f9136c354649e..39fc7800d03a91 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -74,11 +74,11 @@ is compatible with the way these are treated by the :mod:`pickle` module. Shallow copies of many collections can be made using the corresponding :meth:`!copy` method (such as :meth:`list.copy`, :meth:`dict.copy` or -:meth:`set.copy`), and of sequences (lists, bytearrays, etc.) by making a slice -of the entire sequence, for example, ``alist[:]``. -But such methods can create an instance of the base type when copying -an instance of a subclass, whereas :func:`copy.copy` normally returns -an instance of the same type. +:meth:`set.copy`), and of sequences (such as lists or bytearrays) by making +a slice of the entire sequence (``sequence[:]``). +However, these methods and slicing can create an instance of the base type +when copying an instance of a subclass, whereas :func:`copy.copy` normally +returns an instance of the same type. .. index:: pair: module; pickle