Skip to content

Commit

Permalink
reject also keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Sep 25, 2024
1 parent 2dd64c9 commit 467b9cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def make_frame():
FrameLocalsProxy() # no arguments
with self.assertRaises(TypeError):
FrameLocalsProxy(123) # wrong type
with self.assertRaises(TypeError):
FrameLocalsProxy(frame=sys._getframe()) # no keyword arguments


class FrameLocalsProxyMappingTests(mapping_tests.TestHashMappingProtocol):
Expand Down
6 changes: 6 additions & 0 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ framelocalsproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
PyFrameObject *frame = (PyFrameObject*)item;

if (kwds != NULL && PyDict_Size(kwds) != 0) {
PyErr_SetString(PyExc_TypeError,
"FrameLocalsProxy takes no keyword arguments");
return 0;
}

PyFrameLocalsProxyObject *self = (PyFrameLocalsProxyObject *)type->tp_alloc(type, 0);
if (self == NULL) {
return NULL;
Expand Down

0 comments on commit 467b9cb

Please sign in to comment.