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 @@ class SimpleNamespaceTests(unittest.TestCase): 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); }