[Python-checkins] r66352 - in python/trunk: Lib/test/test_weakref.py Misc/NEWS Objects/weakrefobject.c

benjamin.peterson python-checkins at python.org
Tue Sep 9 22:55:01 CEST 2008


Author: benjamin.peterson
Date: Tue Sep  9 22:55:01 2008
New Revision: 66352

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

Reviewers: Amaury, Antoine, Benjamin


Modified:
   python/trunk/Lib/test/test_weakref.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/weakrefobject.c

Modified: python/trunk/Lib/test/test_weakref.py
==============================================================================
--- python/trunk/Lib/test/test_weakref.py	(original)
+++ python/trunk/Lib/test/test_weakref.py	Tue Sep  9 22:55:01 2008
@@ -665,6 +665,14 @@
 
         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):
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Sep  9 22:55:01 2008
@@ -12,6 +12,9 @@
 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

Modified: python/trunk/Objects/weakrefobject.c
==============================================================================
--- python/trunk/Objects/weakrefobject.c	(original)
+++ python/trunk/Objects/weakrefobject.c	Tue Sep  9 22:55:01 2008
@@ -326,7 +326,7 @@
     if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp))
         return 0;
     else
-        return 1;
+        return -1;
 }
 
 


More information about the Python-checkins mailing list