From: Thomas Heller Date: Wed, 24 Oct 2007 19:37:27 +0000 (+0000) Subject: A 'PyObject *' parameter in PyErr_Format must use %S parameter, not %s. X-Git-Tag: v3.0a2~282 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39013cd4c0f76b7b6c34efe4e341618f0ad2027a;p=thirdparty%2FPython%2Fcpython.git A 'PyObject *' parameter in PyErr_Format must use %S parameter, not %s. Added unittest for calling a function with paramflags. --- diff --git a/Lib/ctypes/test/test_prototypes.py b/Lib/ctypes/test/test_prototypes.py index 91b7e0da7d09..e098e7bd7288 100644 --- a/Lib/ctypes/test/test_prototypes.py +++ b/Lib/ctypes/test/test_prototypes.py @@ -48,6 +48,24 @@ class CharPointersTestCase(unittest.TestCase): func.restype = c_long func.argtypes = None + def test_paramflags(self): + # function returns c_void_p result, + # and has a required parameter named 'input' + prototype = CFUNCTYPE(c_void_p, c_void_p) + func = prototype(("_testfunc_p_p", testdll), + ((1, "input"),)) + + try: + func() + except TypeError as details: + self.failUnlessEqual(str(details), "required argument 'input' missing") + else: + self.fail("TypeError not raised") + + self.failUnlessEqual(func(None), None) + self.failUnlessEqual(func(input=None), None) + + def test_int_pointer_arg(self): func = testdll._testfunc_p_p func.restype = c_long diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index f92263030b59..81276faa5d47 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2992,7 +2992,7 @@ _get_arg(int *pindex, PyObject *name, PyObject *defval, PyObject *inargs, PyObje /* we can't currently emit a better error message */ if (name) PyErr_Format(PyExc_TypeError, - "required argument '%s' missing", name); + "required argument '%S' missing", name); else PyErr_Format(PyExc_TypeError, "not enough arguments");