bpo-31655: Validate keyword names in SimpleNamespace constructor. (#3909)
This commit is contained in:
parent
28f713601d
commit
79ba471488
|
@ -1069,6 +1069,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), {})
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue