[3.6] bpo-31655: Validate keyword names in SimpleNamespace constructor. (GH-3909) (#3920)
(cherry picked from commit 79ba471488
)
This commit is contained in:
parent
5f396dba1d
commit
cae6e4775b
|
@ -1051,6 +1051,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), {})
|
||||||
|
|
|
@ -50,8 +50,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue