Skip to content

invalid result value of _weakref.__init__() #47884

Closed

Description

@vstinner
BPO 3634
Nosy @amauryfa, @pitrou, @vstinner, @devdanzin, @benjaminp
Files
  • weakref_init.patch: Fix weakref___init__() return value: -1 on error
  • weakref_test-2.patch: Test .init() using assertRaise()
  • 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/benjaminp'
    closed_at = <Date 2008-09-09.20:56:33.433>
    created_at = <Date 2008-08-21.17:25:00.721>
    labels = ['library']
    title = 'invalid result value of _weakref.__init__()'
    updated_at = <Date 2008-09-09.20:56:33.412>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2008-09-09.20:56:33.412>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-09-09.20:56:33.433>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-21.17:25:00.721>
    creator = 'vstinner'
    dependencies = []
    files = ['11195', '11434']
    hgrepos = []
    issue_num = 3634
    keywords = ['patch']
    message_count = 9.0
    messages = ['71662', '72809', '72811', '72812', '72830', '72833', '72835', '72842', '72909']
    nosy_count = 5.0
    nosy_names = ['amaury.forgeotdarc', 'pitrou', 'vstinner', 'ajaksu2', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3634'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. vstinner commented on Aug 21, 2008

      @vstinner
      MemberAuthor

      _weakref.__init__() doesn't catch errors correctly. Example:
      --------------------- 8< -------------------------

      from gc import collect
      import _weakref
      
      class FuzzingUserClass:
          pass
      
      obj = _weakref.ref(FuzzingUserClass)
      
      # Exception not raised??
      obj.__init__(
          0,
          0,
          0,
      )
      
      # Exception catched here??
      collect()
      --------------------- 8< 

      Attached patch fix the bug for py3k branch: return -1 on error
      (instead of 1).

    2. added
      stdlib
      on Aug 21, 2008
    3. vstinner commented on Sep 8, 2008

      @vstinner
      MemberAuthor

      The bug and the fix are trivials. Can anyone review my patch?

    4. benjaminp commented on Sep 8, 2008

      @benjaminp
      Contributor

      The patch looks absolutely fine to me. (I think I have to have another
      core developer look at it too, though.)

    5. self-assigned this
      on Sep 8, 2008
    6. pitrou commented on Sep 9, 2008

      @pitrou
      Member

      Adding a simple unit test would be nice.

    7. vstinner commented on Sep 9, 2008

      @vstinner
      MemberAuthor

      Add a test to check to regression.

    8. amauryfa commented on Sep 9, 2008

      @amauryfa
      Contributor

      I think the test should check that TypeError is actually raised:
      self.assertRaises(TypeError, r.__init__, 0, 0, 0, 0, 0)
      It's even shorter than the try/except block...

    9. vstinner commented on Sep 9, 2008

      @vstinner
      MemberAuthor

      amaury: oh yes, i forget to use assertRaise(). A new patch is
      attached.

    10. amauryfa commented on Sep 9, 2008

      @amauryfa
      Contributor

      Both patches look fine to me.
      They could be backported to 2.5 as well.

    11. benjaminp commented on Sep 9, 2008

      @benjaminp
      Contributor

      Fixed in r66352.

    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

    Labels

    stdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions