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

WeakValueDictionary constructor ported to Python 3.0 incorrectly #50399

Closed
zzzeek mannequin opened this issue May 30, 2009 · 3 comments
Closed

WeakValueDictionary constructor ported to Python 3.0 incorrectly #50399

zzzeek mannequin opened this issue May 30, 2009 · 3 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@zzzeek
Copy link
Mannequin

zzzeek mannequin commented May 30, 2009

BPO 6149
Nosy @pitrou
Files
  • issue6149.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-30.21:05:29.555>
    created_at = <Date 2009-05-30.20:07:41.981>
    labels = ['library', 'type-crash']
    title = 'WeakValueDictionary constructor ported to Python 3.0 incorrectly'
    updated_at = <Date 2009-05-30.21:05:29.554>
    user = 'https://bugs.python.org/zzzeek'

    bugs.python.org fields:

    activity = <Date 2009-05-30.21:05:29.554>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-05-30.21:05:29.555>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2009-05-30.20:07:41.981>
    creator = 'zzzeek'
    dependencies = []
    files = ['14121']
    hgrepos = []
    issue_num = 6149
    keywords = ['patch']
    message_count = 3.0
    messages = ['88577', '88578', '88581']
    nosy_count = 2.0
    nosy_names = ['pitrou', 'zzzeek']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue6149'
    versions = ['Python 3.1']

    @zzzeek
    Copy link
    Mannequin Author

    zzzeek mannequin commented May 30, 2009

    The constructor for WeakValueDictionary does not obey the contract
    documented in its comments:

    # We inherit the constructor without worrying about the input
    # dictionary; since it uses our .update() method, we get the right
    # checks 
    

    yet it initializes with:

       self.data = d = {}
       d.update(*args, **kw)

    i.e. the "update()" method of dict, so that a dict passed to the
    constructor initializes non-weakrefed values in the dict which is
    completely invalid state.

    Contrast to that of 2.6, which properly uses the superclass:

    UserDict.UserDict.__init__(self, *args, **kw)

    A simple test which raises an exception on 3.0.1 is as follows:

    import weakref
    
    class Foo(object):
        pass
        
    mydict = dict((k, Foo()) for k in range(10))
    
    w = weakref.WeakValueDictionary(mydict)

    assert w[5]

    @zzzeek zzzeek mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels May 30, 2009
    @pitrou
    Copy link
    Member

    pitrou commented May 30, 2009

    Here is a patch for 3.1.

    @pitrou
    Copy link
    Member

    pitrou commented May 30, 2009

    Fixed in r73063. Thanks!

    @pitrou pitrou closed this as completed May 30, 2009
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant