[Python-checkins] [3.6] bpo-31655: Validate keyword names in SimpleNamespace constructor. (GH-3909) (#3920)
Serhiy Storchaka
webhook-mailer at python.org
Sat Oct 7 16:53:01 EDT 2017
https://github.com/python/cpython/commit/cae6e4775b37c412609d3a0d303c0831ff0012ff
commit: cae6e4775b37c412609d3a0d303c0831ff0012ff
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017年10月07日T23:52:57+03:00
summary:
[3.6] bpo-31655: Validate keyword names in SimpleNamespace constructor. (GH-3909) (#3920)
(cherry picked from commit 79ba471488b936abda5ba5234b1ea90cbc94cae6)
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 d79429faf11..73fbdbf9b90 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -1051,6 +1051,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 0bb30638445..d28c9133b4b 100644
--- a/Objects/namespaceobject.c
+++ b/Objects/namespaceobject.c
@@ -50,8 +50,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
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