Commits

Armin Rigo committed 36da3ef

Simplify this error message

  • Participants
  • Parent commits 9aa039e

Comments (0)

Files changed (2)

File c/_cffi_backend.c

     if (cif_descr != NULL) {
         /* regular case: this function does not take '...' arguments */
         if (nargs != nargs_declared) {
-            errormsg = "%s expects %zd arguments, got %zd";
+            errormsg = "'%s' expects %zd arguments, got %zd";
             goto bad_number_of_arguments;
         }
     }
         /* call of a variadic function */
         ffi_abi fabi;
         if (nargs < nargs_declared) {
-            errormsg = "%s expects at least %zd arguments, got %zd";
+            errormsg = "'%s' expects at least %zd arguments, got %zd";
             goto bad_number_of_arguments;
         }
         fvarargs = PyTuple_New(nargs);
     return res;
 
  bad_number_of_arguments:
-    {
-        PyObject *s = Py_TYPE(cd)->tp_repr((PyObject *)cd);
-        if (s != NULL) {
-            PyErr_Format(PyExc_TypeError, errormsg,
-                         PyString_AS_STRING(s), nargs_declared, nargs);
-            Py_DECREF(s);
-        }
-        goto error;
-    }
-
+    PyErr_Format(PyExc_TypeError, errormsg,
+                 cd->c_type->ct_name, nargs_declared, nargs);
  error:
     if (buffer)
         PyObject_Free(buffer);
     assert repr(f).startswith(
         "<cdata 'int(*)(int)' calling <function cb at 0x")
     e = py.test.raises(TypeError, f)
-    assert str(e.value) == "%r expects 1 arguments, got 0" % (f,)
+    assert str(e.value) == "'int(*)(int)' expects 1 arguments, got 0"
 
 def test_callback_return_type():
     for rettype in ["signed char", "short", "int", "long", "long long",