8000 bpo-42576: Raise TypeError when passing in keyword arguments to Gener… · python/cpython@804d689 · GitHub
[go: up one dir, main page]

Skip to content

Commit 804d689

Browse files
bpo-42576: Raise TypeError when passing in keyword arguments to GenericAlias (GH-23656)
Use `_PyArg_NoKeywords` instead of `_PyArg_NoKwnames` when checking the `kwds` tuple when creating `GenericAlias`. This fixes an interpreter crash when passing in keyword arguments to `GenericAlias`'s constructor. Needs backport to 3.9. Automerge-Triggered-By: GH:gvanrossum
1 parent da3d2ab commit 804d689

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/test/test_genericalias.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ def test_weakref(self):
302302
alias = t[int]
303303
self.assertEqual(ref(alias)(), alias)
304304

305+
def test_no_kwargs(self):
306+
# bpo-42576
307+
with self.assertRaises(TypeError):
308+
GenericAlias(bad=float)
309+
305310

306311
if __name__ == "__main__":
307312
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``types.GenericAlias`` will now raise a ``TypeError`` when attempting to
2+
initialize with a keyword argument. Previously, this would cause the
3+
interpreter to crash. Patch by Ken Jin.

Objects/genericaliasobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static PyGetSetDef ga_properties[] = {
567567
static PyObject *
568568
ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
569569
{
570-
if (!_PyArg_NoKwnames("GenericAlias", kwds)) {
570+
if (!_PyArg_NoKeywords("GenericAlias", kwds)) {
571571
return NULL;
572572
}
573573
if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) {

0 commit comments

Comments
 (0)
0