Kaydet (Commit) cae6e477 authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) Serhiy Storchaka

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

(cherry picked from commit 79ba4714)
üst 5f396dba
......@@ -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), {})
......
......@@ -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);
}
......
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