Skip to content

The range() object is deepcopied as atomic #70390

Closed

Description

@serhiy-storchaka
BPO 26202
Nosy @freddrake, @vstinner, @avassalotti, @ethanfurman, @serhiy-storchaka
Files
  • deepcopy_range.patch
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-01-28.19:46:46.805>
    created_at = <Date 2016-01-25.20:53:06.176>
    labels = ['type-bug', 'library']
    title = 'The range() object is deepcopied as atomic'
    updated_at = <Date 2020-05-28.08:15:50.321>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-05-28.08:15:50.321>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-01-28.19:46:46.805>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-01-25.20:53:06.176>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['41714']
    hgrepos = []
    issue_num = 26202
    keywords = ['patch']
    message_count = 10.0
    messages = ['258921', '258925', '258926', '258927', '258929', '258930', '259154', '259155', '370167', '370174']
    nosy_count = 6.0
    nosy_names = ['fdrake', 'vstinner', 'alexandre.vassalotti', 'ethan.furman', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26202'
    versions = ['Python 3.5', 'Python 3.6']

    Activity

    1. serhiy-storchaka commented on Jan 25, 2016

      @serhiy-storchaka
      MemberAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 25, 2016
    3. vstinner commented on Jan 25, 2016

      @vstinner
      Member

      Hum ok, it's a bug :-) It should be fixed. Do you want to work on a patch?

    4. ethanfurman commented on Jan 25, 2016

      @ethanfurman
      Member

      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?

    5. ethanfurman commented on Jan 25, 2016

      @ethanfurman
      Member

      Victor, patch was already attached. ;)

    6. vstinner commented on Jan 25, 2016

      @vstinner
      Member

      deepcopy_range.patch looks good to me.

    7. serhiy-storchaka commented on Jan 25, 2016

      @serhiy-storchaka
      MemberAuthor

      Returning the same range() object from copy.copy() is correct. This is shallow copying.

    8. python-dev commented on Jan 28, 2016

      python-devmannequin
      Mannequin

      New changeset 5772eae17a82 by Serhiy Storchaka in branch '3.5':
      Issue bpo-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 bpo-26202: copy.deepcopy() now correctly copies range() objects with
      https://hg.python.org/cpython/rev/d5d0b62c2830

    9. serhiy-storchaka commented on Jan 28, 2016

      @serhiy-storchaka
      MemberAuthor

      Thanks Victor.

    10. serhiy-storchaka commented on May 28, 2020

      @serhiy-storchaka
      MemberAuthor

      New changeset 5f4b229 by Serhiy Storchaka in branch 'master':
      bpo-40792: Make the result of PyNumber_Index() always having exact type int. (GH-20443)
      5f4b229

    11. serhiy-storchaka commented on May 28, 2020

      @serhiy-storchaka
      MemberAuthor

      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.

    12. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions