From: Serhiy Storchaka Date: Sat, 7 May 2016 12:41:09 +0000 (+0300) Subject: Issue #17765: weakref.ref() no longer silently ignores keyword arguments. X-Git-Tag: v3.6.0a1~64^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21eb48764c618eede0405ef840eadf1b03ff9b00;p=python Issue #17765: weakref.ref() no longer silently ignores keyword arguments. Patch by Georg Brandl. --- diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index f37f1e9e24..f49cb7e591 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -133,6 +133,10 @@ class ReferencesTestCase(TestBase): ref1 = weakref.ref(c, callback) del c + def test_constructor_kwargs(self): + c = C() + self.assertRaises(TypeError, weakref.ref, c, callback=None) + def test_proxy_ref(self): o = C() o.bar = 1 diff --git a/Misc/NEWS b/Misc/NEWS index 18995f13ae..3d0a4d041b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -116,6 +116,9 @@ Core and Builtins Library ------- +- Issue #17765: weakref.ref() no longer silently ignores keyword arguments. + Patch by Georg Brandl. + - Issue #26873: xmlrpc now raises ResponseError on unsupported type tags instead of silently return incorrect result. diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index d4d52e60ae..7e6f36458b 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -268,7 +268,6 @@ static int parse_weakref_init_args(char *funcname, PyObject *args, PyObject *kwargs, PyObject **obp, PyObject **callbackp) { - /* XXX Should check that kwargs == NULL or is empty. */ return PyArg_UnpackTuple(args, funcname, 1, 2, obp, callbackp); } @@ -331,6 +330,9 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject *tmp; + if (!_PyArg_NoKeywords("ref()", kwargs)) + return -1; + if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp)) return 0; else