Skip to content
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

weakref copy module interaction #46370

Closed
rharris mannequin opened this issue Feb 14, 2008 · 9 comments
Closed

weakref copy module interaction #46370

rharris mannequin opened this issue Feb 14, 2008 · 9 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rharris
Copy link
Mannequin

rharris mannequin commented Feb 14, 2008

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']

    @rharris
    Copy link
    Mannequin Author

    rharris mannequin commented Feb 14, 2008

    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)

    @rharris rharris mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Feb 14, 2008
    @jafo
    Copy link
    Mannequin

    jafo mannequin commented Mar 19, 2008

    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.

    @jafo jafo mannequin assigned tim-one Mar 19, 2008
    @jafo jafo mannequin added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Mar 19, 2008
    @rharris
    Copy link
    Mannequin Author

    rharris mannequin commented Apr 4, 2008

    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.

    @pitrou
    Copy link
    Member

    pitrou commented Mar 14, 2009

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

    @pitrou
    Copy link
    Member

    pitrou commented Mar 14, 2009

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

    @pitrou
    Copy link
    Member

    pitrou commented Mar 15, 2009

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

    @pitrou
    Copy link
    Member

    pitrou commented Mar 15, 2009

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

    @pitrou
    Copy link
    Member

    pitrou commented May 1, 2009

    Raymond, Guido, any opinion on this one?

    @pitrou
    Copy link
    Member

    pitrou commented May 15, 2009

    Committed in r72662, r72670. Thanks!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants