]> granicus.if.org Git - python/commitdiff
Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 7 May 2016 12:41:09 +0000 (15:41 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 7 May 2016 12:41:09 +0000 (15:41 +0300)
Patch by Georg Brandl.

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

index b7f985c939a770a9fb534e9fe3a94ba700c08e11..4073d495fd161585302a4dd7b968dcd9426fb4e8 100644 (file)
@@ -116,6 +116,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
index 0c2fb0b0bd2a73359101397e21e9857edd2492c5..cca6266f6153448f8383ffb009110d0539344ac3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
+  Patch by Georg Brandl.
+
 - Issue #26873: xmlrpclib now raises ResponseError on unsupported type tags
   instead of silently return incorrect result.
 
index e1f4bc42c2427a88065847579127667c4d70635a..c8b982fcd59ce823b3f9bc0e81e707fd58c1a014 100644 (file)
@@ -271,7 +271,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);
 }
 
@@ -334,6 +333,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