-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Bug report
Bug description:
copy.copy() and copy.deepcopy() don't copy a range as shown below:
import copy
v1 = range(5)
v2 = copy.copy(v1)
v2 = copy.deepcopy(v1)
print(v1 is v2)
# True
But slicing copies a range as shown below:
v1 = range(5)
v2 = v1[:]
print(v1 is v2)
# False
Basically, a shallow or deep copy operation with copy.copy()
, slicing
or copy.deepcopy()
doesn't create a copy for an immutable object like a tuple, string or bytes to avoid wasting memory but only slicing copies a range even though copy.copy()
and copy.deepcopy()
don't copy a range.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement