[3.6] bpo-31655: Validate keyword names in SimpleNamespace constructor. (GH-3909) (#3920)

(cherry picked from commit 79ba471488)
This commit is contained in:
Miss Islington (bot) 2017-10-07 13:52:57 -07:00 committed by Serhiy Storchaka
parent 5f396dba1d
commit cae6e4775b
2 changed files with 7 additions and 1 deletions

View File

@ -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), {})

View File

@ -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);
}