Issue26202
Created on 2016-01-25 20:53 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| deepcopy_range.patch | serhiy.storchaka, 2016-01-25 20:53 | review | ||
| Messages (10) | |||
|---|---|---|---|
| msg258921 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-01-25 20:53 | |
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. |
|||
| msg258925 - (view) | Author: STINNER Victor (vstinner) * | Date: 2016-01-25 21:23 | |
Hum ok, it's a bug :-) It should be fixed. Do you want to work on a patch? |
|||
| msg258926 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2016-01-25 21:24 | |
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? |
|||
| msg258927 - (view) | Author: Ethan Furman (ethan.furman) * | Date: 2016-01-25 21:25 | |
Victor, patch was already attached. ;) |
|||
| msg258929 - (view) | Author: STINNER Victor (vstinner) * | Date: 2016-01-25 21:44 | |
deepcopy_range.patch looks good to me. |
|||
| msg258930 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-01-25 21:47 | |
Returning the same range() object from copy.copy() is correct. This is shallow copying. |
|||
| msg259154 - (view) | Author: Roundup Robot (python-dev) | Date: 2016-01-28 19:44 | |
New changeset 5772eae17a82 by Serhiy Storchaka in branch '3.5': Issue #26202: copy.deepcopy() now correctly copies range() objects with https://hg.python.org/cpython/rev/5772eae17a82 New changeset d5d0b62c2830 by Serhiy Storchaka in branch 'default': Issue #26202: copy.deepcopy() now correctly copies range() objects with https://hg.python.org/cpython/rev/d5d0b62c2830 |
|||
| msg259155 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-01-28 19:46 | |
Thanks Victor. |
|||
| msg370167 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2020-05-28 07:34 | |
New changeset 5f4b229df7812f1788287095eb6b138bb21876a4 by Serhiy Storchaka in branch 'master': bpo-40792: Make the result of PyNumber_Index() always having exact type int. (GH-20443) https://github.com/python/cpython/commit/5f4b229df7812f1788287095eb6b138bb21876a4 |
|||
| msg370174 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2020-05-28 08:15 | |
This change has been reverted in issue40792. The range object attributes has now exact type int, so the original issue with deep copying is gone. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:26 | admin | set | github: 70390 |
| 2020-05-28 08:15:50 | serhiy.storchaka | set | messages: + msg370174 |
| 2020-05-28 07:34:43 | serhiy.storchaka | set | messages: + msg370167 |
| 2016-01-28 19:46:46 | serhiy.storchaka | set | status: open -> closed messages: + msg259155 assignee: serhiy.storchaka |
| 2016-01-28 19:44:43 | python-dev | set | nosy:
+ python-dev messages: + msg259154 |
| 2016-01-25 21:47:24 | serhiy.storchaka | set | messages: + msg258930 |
| 2016-01-25 21:44:51 | vstinner | set | messages: + msg258929 |
| 2016-01-25 21:25:18 | ethan.furman | set | messages: + msg258927 |
| 2016-01-25 21:24:46 | ethan.furman | set | nosy:
+ ethan.furman messages: + msg258926 |
| 2016-01-25 21:23:00 | vstinner | set | messages: + msg258925 |
| 2016-01-25 20:53:06 | serhiy.storchaka | create | |