]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
A 'PyObject *' parameter in PyErr_Format must use %S parameter, not %s.
authorThomas Heller <theller@ctypes.org>
Wed, 24 Oct 2007 19:37:27 +0000 (19:37 +0000)
committerThomas Heller <theller@ctypes.org>
Wed, 24 Oct 2007 19:37:27 +0000 (19:37 +0000)
Added unittest for calling a function with paramflags.

Lib/ctypes/test/test_prototypes.py
Modules/_ctypes/_ctypes.c

index 91b7e0da7d09b3ade51507cf925d6d2c4bdd4c64..e098e7bd728879c78f9cd66338ef9f353bf91202 100644 (file)
@@ -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
index f92263030b599446dfafe743d3b09fe819b5741e..81276faa5d47fd41ffd3d492cd7a03d728393204 100644 (file)
@@ -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");