What I normally do is have two C functions that take the different arguments. The "python-facing" function's job is to parse out the arguments, call the appropriate C function, and build the return value if any.
This is pretty common when, for example, you want to allow both byte and Unicode strings.
Here is an example of what I mean.
// Silly example: get the length of a string, supporting Unicode and byte strings
static PyObject* getlen_py(PyObject *self, PyObject *args)
{
// Unpack our argument (error handling omitted...)
PyObject *arg = NULL;
PyArg_UnpackTuple(args, "getlen", 1, 1, arg) ;
if ( PyUnicode_Check(arg) )
{
// It's a Unicode string
return PyInt_FromLong(getlen_w(PyUnicode_AS_UNICODE(arg))) ;
}
else
{
// It's a byte string
return PyInt_FromLong(getlen_a(PyString_AS_STRING(arg))) ;
}
}