Ich schreibe C-Extensions, und ich möchte die Signatur meiner Methoden für Introspektion sichtbar machen.Python C-Erweiterung: Methodensignaturen für die Dokumentation?
static PyObject* foo(PyObject *self, PyObject *args) {
/* blabla [...] */
}
PyDoc_STRVAR(
foo_doc,
"Great example function\n"
"Arguments: (timeout, flags=None)\n"
"Doc blahblah doc doc doc.");
static PyMethodDef methods[] = {
{"foo", foo, METH_VARARGS, foo_doc},
{NULL},
};
PyMODINIT_FUNC init_myexample(void) {
(void) Py_InitModule3("_myexample", methods, "a simple example module");
}
Wenn nun (nach dem Bau ...) ich das Modul laden und auf seine Hilfe suchen:
>>> import _myexample
>>> help(_myexample)
ich bekommen:
Help on module _myexample:
NAME
_myexample - a simple example module
FILE
/path/to/module/_myexample.so
FUNCTIONS
foo(...)
Great example function
Arguments: (timeout, flags=None)
Doc blahblah doc doc doc.
Ich möchte sein noch spezifischer und in der Lage zu ersetzen foo (...) von foo (Timeout, Flags = Keine)
Kann ich das tun? Wie?
funktioniert das mit 'inspect.signature'? – Eric
@Eric Ja, solange es den oben genannten Regeln von "__text_signature__" entspricht. – MSeifert
Klingt wie eine Sache, dass 'numpy' einen Patch für – Eric