-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
The range() object is deepcopied as atomic #70390
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
Comments
The range() object is immutable, but is not atomic, and copy.deepcopy() shouldn't return it unchanged. >>> class I(int): pass # mutable index
...
>>> import copy
>>> r = range(I(10))
>>> r2 = copy.deepcopy(r)
>>> r.stop.attr = 'spam'
>>> r2.stop.attr
'spam' This is Python 3 only issue because in 2.7 the xrange() object doesn't exposes start/stop/step attributes. Proposed patch fixes the copy module. |
Hum ok, it's a bug :-) It should be fixed. Do you want to work on a patch? |
I don't have much experience with the copy module, but I don't see any problems with the code. Does copy.copy suffer from the same problem? If yes, is it fixed with this same patch, or is more work needed? |
Victor, patch was already attached. ;) |
deepcopy_range.patch looks good to me. |
Returning the same range() object from copy.copy() is correct. This is shallow copying. |
New changeset 5772eae17a82 by Serhiy Storchaka in branch '3.5': New changeset d5d0b62c2830 by Serhiy Storchaka in branch 'default': |
Thanks Victor. |
This change has been reverted in bpo-40792. The range object attributes has now exact type int, so the original issue with deep copying is gone. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: