Skip to content

WeakValueDictionary constructor ported to Python 3.0 incorrectly #50399

Closed

Description

@zzzeek
mannequin
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']

    Activity

    1. zzzeek commented on May 30, 2009

      zzzeekmannequin
      MannequinAuthor

      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]

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-crashA hard crash of the interpreter, possibly with a core dump
      on May 30, 2009
    3. pitrou commented on May 30, 2009

      @pitrou
      Member

      Here is a patch for 3.1.

    4. pitrou commented on May 30, 2009

      @pitrou
      Member

      Fixed in r73063. Thanks!

    5. 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-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions