Fix #3634 invalid return value from _weakref.ref(Exception).__init__

Reviewers: Amaury, Antoine, Benjamin
This commit is contained in:
Benjamin Peterson 2008-09-09 20:55:01 +00:00
parent c0f10f34b1
commit 97179b0f58
3 changed files with 12 additions and 1 deletions

View File

@ -665,6 +665,14 @@ class ReferencesTestCase(TestBase):
w = Target() w = Target()
def test_init(self):
# Issue 3634
# <weakref to class>.__init__() doesn't check errors correctly
r = weakref.ref(Exception)
self.assertRaises(TypeError, r.__init__, 0, 0, 0, 0, 0)
# No exception should be raised here
gc.collect()
class SubclassableWeakrefTestCase(TestBase): class SubclassableWeakrefTestCase(TestBase):

View File

@ -12,6 +12,9 @@ What's New in Python 2.6 release candidate 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #3634: _weakref.ref(Exception).__init__() gave invalid return value on
error.
- Issue #3777: long() applied to a float object now always return a long - Issue #3777: long() applied to a float object now always return a long
object; previously an int would be returned for small values. the __long__ object; previously an int would be returned for small values. the __long__
method is allowed to return either an int or a long, but the behaviour of method is allowed to return either an int or a long, but the behaviour of

View File

@ -326,7 +326,7 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp)) if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp))
return 0; return 0;
else else
return 1; return -1;
} }