From 97179b0f58ebb13c6053096dc9fb7aff9f4abf33 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Tue, 9 Sep 2008 20:55:01 +0000 Subject: Fix #3634 invalid return value from _weakref.ref(Exception).__init__ Reviewers: Amaury, Antoine, Benjamin --- Lib/test/test_weakref.py | 8 ++++++++ Misc/NEWS | 3 +++ Objects/weakrefobject.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index c70804e..aeafdda 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -665,6 +665,14 @@ class ReferencesTestCase(TestBase): w = Target() + def test_init(self): + # Issue 3634 + # .__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): diff --git a/Misc/NEWS b/Misc/NEWS index 1fca795..4a201f2 100644 --- 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 diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 5cd9173..9cdd021 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -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; } -- cgit v0.12