Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39013cd

Browse files
author
Thomas Heller
committed
A 'PyObject *' parameter in PyErr_Format must use %S parameter, not %s.
Added unittest for calling a function with paramflags.
1 parent bd1c68c commit 39013cd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Lib/ctypes/test/test_prototypes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ def setUp(self):
4848
func.restype = c_long
4949
func.argtypes = None
5050

51+
def test_paramflags(self):
52+
# function returns c_void_p result,
53+
# and has a required parameter named 'input'
54+
prototype = CFUNCTYPE(c_void_p, c_void_p)
55+
func = prototype(("_testfunc_p_p", testdll),
56+
((1, "input"),))
57+
58+
try:
59+
func()
60+
except TypeError as details:
61+
self.failUnlessEqual(str(details), "required argument 'input' missing")
62+
else:
63+
self.fail("TypeError not raised")
64+
65+
self.failUnlessEqual(func(None), None)
66+
self.failUnlessEqual(func(input=None), None)
67+
68+
5169
def test_int_pointer_arg(self):
5270
func = testdll._testfunc_p_p
5371
func.restype = c_long

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2992,7 +2992,7 @@ _get_arg(int *pindex, PyObject *name, PyObject *defval, PyObject *inargs, PyObje
29922992
/* we can't currently emit a better error message */
29932993
if (name)
29942994
PyErr_Format(PyExc_TypeError,
2995-
"required argument '%s' missing", name);
2995+
"required argument '%S' missing", name);
29962996
else
29972997
PyErr_Format(PyExc_TypeError,
29982998
"not enough arguments");

0 commit comments

Comments
 (0)