Skip to content

Commit cae6e47

Browse files
miss-islingtonserhiy-storchaka
authored andcommitted
[3.6] bpo-31655: Validate keyword names in SimpleNamespace constructor. (GH-3909) (#3920)
(cherry picked from commit 79ba471)
1 parent 5f396db commit cae6e47

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/test_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,8 @@ def test_constructor(self):
10511051

10521052
with self.assertRaises(TypeError):
10531053
types.SimpleNamespace(1, 2, 3)
1054+
with self.assertRaises(TypeError):
1055+
types.SimpleNamespace(**{1: 2})
10541056

10551057
self.assertEqual(len(ns1.__dict__), 0)
10561058
self.assertEqual(vars(ns1), {})

Objects/namespaceobject.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ namespace_init(_PyNamespaceObject *ns, PyObject *args, PyObject *kwds)
5050
return -1;
5151
}
5252
}
53-
if (kwds == NULL)
53+
if (kwds == NULL) {
5454
return 0;
55+
}
56+
if (!PyArg_ValidateKeywordArguments(kwds)) {
57+
return -1;
58+
}
5559
return PyDict_Update(ns->ns_dict, kwds);
5660
}
5761

0 commit comments

Comments
 (0)