Kaydet (Commit) 79ba4714 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

bpo-31655: Validate keyword names in SimpleNamespace constructor. (#3909)

üst 28f71360
...@@ -1069,6 +1069,8 @@ class SimpleNamespaceTests(unittest.TestCase): ...@@ -1069,6 +1069,8 @@ class SimpleNamespaceTests(unittest.TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
types.SimpleNamespace(1, 2, 3) types.SimpleNamespace(1, 2, 3)
with self.assertRaises(TypeError):
types.SimpleNamespace(**{1: 2})
self.assertEqual(len(ns1.__dict__), 0) self.assertEqual(len(ns1.__dict__), 0)
self.assertEqual(vars(ns1), {}) self.assertEqual(vars(ns1), {})
......
...@@ -44,8 +44,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds) ...@@ -44,8 +44,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
PyErr_Format(PyExc_TypeError, "no positional arguments expected"); PyErr_Format(PyExc_TypeError, "no positional arguments expected");
return -1; return -1;
} }
if (kwds == NULL) if (kwds == NULL) {
return 0; return 0;
}
if (!PyArg_ValidateKeywordArguments(kwds)) {
return -1;
}
return PyDict_Update(ns->ns_dict, kwds); return PyDict_Update(ns->ns_dict, kwds);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment