Issue #17765: weakref.ref() no longer silently ignores keyword arguments.

Patch by Georg Brandl.
This commit is contained in:
Serhiy Storchaka 2016-05-07 15:43:59 +03:00
commit 17e22959a4
3 changed files with 10 additions and 1 deletions

View File

@ -133,6 +133,10 @@ class ReferencesTestCase(TestBase):
ref1 = weakref.ref(c, callback) ref1 = weakref.ref(c, callback)
del c del c
def test_constructor_kwargs(self):
c = C()
self.assertRaises(TypeError, weakref.ref, c, callback=None)
def test_proxy_ref(self): def test_proxy_ref(self):
o = C() o = C()
o.bar = 1 o.bar = 1

View File

@ -265,6 +265,9 @@ Core and Builtins
Library 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 - Issue #26873: xmlrpc now raises ResponseError on unsupported type tags
instead of silently return incorrect result. instead of silently return incorrect result.

View File

@ -268,7 +268,6 @@ static int
parse_weakref_init_args(const char *funcname, PyObject *args, PyObject *kwargs, parse_weakref_init_args(const char *funcname, PyObject *args, PyObject *kwargs,
PyObject **obp, PyObject **callbackp) PyObject **obp, PyObject **callbackp)
{ {
/* XXX Should check that kwargs == NULL or is empty. */
return PyArg_UnpackTuple(args, funcname, 1, 2, obp, callbackp); return PyArg_UnpackTuple(args, funcname, 1, 2, obp, callbackp);
} }
@ -331,6 +330,9 @@ weakref___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{ {
PyObject *tmp; PyObject *tmp;
if (!_PyArg_NoKeywords("ref()", kwargs))
return -1;
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