Skip to content

weakref copy module interaction #46370

Closed
Closed

Description

@rharris
mannequin
BPO 2116
Nosy @gvanrossum, @tim-one, @rhettinger, @pitrou
Files
  • copy.patch: Possible patch to fix this
  • issue2116.patch
  • issue2116-2.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 = None
    closed_at = <Date 2009-05-15.17:06:04.165>
    created_at = <Date 2008-02-14.21:22:34.187>
    labels = ['type-bug', 'library']
    title = 'weakref copy module interaction'
    updated_at = <Date 2009-05-15.17:06:04.163>
    user = 'https://bugs.python.org/rharris'

    bugs.python.org fields:

    activity = <Date 2009-05-15.17:06:04.163>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-05-15.17:06:04.165>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2008-02-14.21:22:34.187>
    creator = 'rharris'
    dependencies = []
    files = ['9433', '13334', '13335']
    hgrepos = []
    issue_num = 2116
    keywords = ['patch']
    message_count = 9.0
    messages = ['62413', '64101', '64909', '83606', '83607', '83609', '83612', '86917', '87822']
    nosy_count = 6.0
    nosy_names = ['gvanrossum', 'tim.peters', 'rhettinger', 'jafo', 'pitrou', 'rharris']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2116'
    versions = ['Python 3.1', 'Python 2.7']

    Activity

    1. rharris commented on Feb 14, 2008

      rharrismannequin
      MannequinAuthor

      The copy module will not properly copy/deepcopy weakrefs, it will bomb
      out with __new__ not having enough args. This is a problem b/c it makes
      deepcopying of objects that make use of Weak(Key|Value)Dictionaries
      difficult.

      To replicate:

      import copy, weakref
      class Test(object): pass
      t = Test()
      wr = weakref.ref(t)
      wr_new = copy.copy(wr)
    2. added
      type-crashA hard crash of the interpreter, possibly with a core dump
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 14, 2008
    3. jafo commented on Mar 19, 2008

      jafomannequin
      Mannequin

      Rick: In the future, please provide a context or unified diff ("diff
      -c") so that we get the file name that the diff is for and some
      additional context.

    4. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Mar 19, 2008
    5. rharris commented on Apr 4, 2008

      rharrismannequin
      MannequinAuthor

      Sorry about forgetting the -c arg! The patch is intended for
      python/trunk/Lib/copy.py.

      It looks like Raymond Hettinger has made a similar-ish change recently
      to make Ellipsis copyable.

    6. pitrou commented on Mar 14, 2009

      @pitrou
      Member

      Should a deepcopy of a weakref return the same weakref, or a weakref to
      a new copied object?
      Also, what about the optional callback?

    7. pitrou commented on Mar 14, 2009

      @pitrou
      Member

      Hmm, forget that question. If we deepcopy the weakref target, it will be
      destroyed just afterwards, making the deepcopied weakref useless.

    8. pitrou commented on Mar 15, 2009

      @pitrou
      Member

      Here is a patch providing proper copy and deepcopy support, including
      for weak dicts (the Proxy type is unsupported, though).

    9. pitrou commented on Mar 15, 2009

      @pitrou
      Member

      Updated patch so that copied weakdicts are decoupled (adding an item to
      the copy doesn't mutate the original).

    10. pitrou commented on May 1, 2009

      @pitrou
      Member

      Raymond, Guido, any opinion on this one?

    11. pitrou commented on May 15, 2009

      @pitrou
      Member

      Committed in r72662, r72670. Thanks!

    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

    Assignees

    No one assigned

      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