[Python-checkins] bpo-31655: Validate keyword names in SimpleNamespace constructor. (#3909)
Serhiy Storchaka
webhook-mailer at python.org
Sat Oct 7 15:59:40 EDT 2017
https://github.com/python/cpython/commit/79ba471488b936abda5ba5234b1ea90cbc94cae6
commit: 79ba471488b936abda5ba5234b1ea90cbc94cae6
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-10-07T22:59:35+03:00
summary:
bpo-31655: Validate keyword names in SimpleNamespace constructor. (#3909)
files:
M Lib/test/test_types.py
M Objects/namespaceobject.c
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 966ef6d8782..28133a3560f 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -1069,6 +1069,8 @@ def test_constructor(self):
with self.assertRaises(TypeError):
types.SimpleNamespace(1, 2, 3)
+ with self.assertRaises(TypeError):
+ types.SimpleNamespace(**{1: 2})
self.assertEqual(len(ns1.__dict__), 0)
self.assertEqual(vars(ns1), {})
diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c
index 6deca961a4f..e5698e6378d 100644
--- a/Objects/namespaceobject.c
+++ b/Objects/namespaceobject.c
@@ -44,8 +44,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
PyErr_Format(PyExc_TypeError, "no positional arguments expected");
return -1;
}
- if (kwds == NULL)
+ if (kwds == NULL) {
return 0;
+ }
+ if (!PyArg_ValidateKeywordArguments(kwds)) {
+ return -1;
+ }
return PyDict_Update(ns->ns_dict, kwds);
}
More information about the Python-checkins
mailing list