Skip to content

Commit

Permalink
bpo-42576: Raise TypeError when passing in keyword arguments to Gener…
Browse files Browse the repository at this point in the history
…icAlias (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
  • Loading branch information
Fidget-Spinner committed Dec 5, 2020
1 parent da3d2ab commit 804d689
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Lib/test/test_genericalias.py
Expand Up @@ -302,6 +302,11 @@ def test_weakref(self):
alias = t[int]
self.assertEqual(ref(alias)(), alias)

def test_no_kwargs(self):
# bpo-42576
with self.assertRaises(TypeError):
GenericAlias(bad=float)


if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,3 @@
``types.GenericAlias`` will now raise a ``TypeError`` when attempting to
initialize with a keyword argument. Previously, this would cause the
interpreter to crash. Patch by Ken Jin.
2 changes: 1 addition & 1 deletion Objects/genericaliasobject.c
Expand Up @@ -567,7 +567,7 @@ static PyGetSetDef ga_properties[] = {
static PyObject *
ga_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
if (!_PyArg_NoKwnames("GenericAlias", kwds)) {
if (!_PyArg_NoKeywords("GenericAlias", kwds)) {
return NULL;
}
if (!_PyArg_CheckPositional("GenericAlias", PyTuple_GET_SIZE(args), 2, 2)) {
Expand Down

0 comments on commit 804d689

Please sign in to comment.