[Python-checkins] cpython (merge 3.5 -> default): Issue #17765: weakref.ref() no longer silently ignores keyword arguments.

serhiy.storchaka python-checkins at python.org
Sat May 7 08:44:38 EDT 2016


https://hg.python.org/cpython/rev/ef55fa8c4b82
changeset:   101253:ef55fa8c4b82
parent:      101249:3ceb54a49387
parent:      101251:ee17a83feabc
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat May 07 15:43:59 2016 +0300
summary:
  Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
Patch by Georg Brandl.

files:
  Lib/test/test_weakref.py |  4 ++++
  Misc/NEWS                |  3 +++
  Objects/weakrefobject.c  |  4 +++-
  3 files changed, 10 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -133,6 +133,10 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -265,6 +265,9 @@
 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
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -268,7 +268,6 @@
 parse_weakref_init_args(const 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 @@
 {
     PyObject *tmp;
 
+    if (!_PyArg_NoKeywords("ref()", kwargs))
+        return -1;
+
     if (parse_weakref_init_args("__init__", args, kwargs, &tmp, &tmp))
         return 0;
     else

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list