]> granicus.if.org Git - python/commitdiff
Fix #3634 invalid return value from _weakref.ref(Exception).__init__
authorBenjamin Peterson <benjamin@python.org>
Tue, 9 Sep 2008 20:55:01 +0000 (20:55 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 9 Sep 2008 20:55:01 +0000 (20:55 +0000)
Reviewers: Amaury, Antoine, Benjamin

Lib/test/test_weakref.py
Misc/NEWS
Objects/weakrefobject.c

index c70804e829e38dad7cc7f2fc1eb166fe3618d4b8..aeafddab72dbb8f493a2fe8738bbde0d17117b1a 100644 (file)
@@ -665,6 +665,14 @@ class ReferencesTestCase(TestBase):
 
         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):
 
index 1fca7958fbfa9486e177aff3501743b08add3d56..4a201f2f0b073f05dc7141fb0b54a4dd00e5f029 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 release candidate 1?
 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
   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
index 5cd91734e4e76821ddf611ac510ca50a49126213..9cdd02178d7083cbb6e0a74cca13712c00df97cb 100644 (file)
@@ -326,7 +326,7 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp))
         return 0;
     else
-        return 1;
+        return -1;
 }