diff options
author | Christian Tismer <tismer@stackless.com> | 2019-01-16 13:11:31 +0100 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2019-01-18 13:22:36 +0100 |
commit | 6371c1d419e9089226b3179031a9ee525033e2ea (patch) | |
tree | e946354c375d2440fdefe839bbca56c9aed61a86 /sources/shiboken2/libshiboken | |
parent | 077db7a4a432c78490ae34ead3f1d5338175b81c (diff) |
Complete the help() support for Types
The help() support based upon the Signature module worked
fine but for types.
The reason was that the __signature__ module was a new attribute,
while __doc__ already existed through an inheritance-like
mechanism. When we add __doc__ later, the attributes are already
in the cache. PyType_Modified(type) does not help in PySide.
The solution was to add tp_getset to the metaclass
SbkObjectType_Type which otherwise would have been reached
from PyType_Type ('type' in Python).
Note.. It makes sense to add the injected documentation to the
__doc__ strings as well. This enables help output even with
the py_doc web service!
Task-number: PYSIDE-908
Change-Id: I09dd4bc6746ee41566a467604c4a68de5d66f94b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 10 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/signature.cpp | 20 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/signature.h | 2 |
3 files changed, 32 insertions, 0 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index faaca5e4b..f38b55b56 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -76,11 +76,21 @@ extern "C" static void SbkObjectTypeDealloc(PyObject* pyObj); static PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds); +// PYSIDE-908: The function PyType_Modified does not work in PySide, so we need to +// explicitly pass __doc__. For __signature__ it _did_ actually work, because +// it was not existing before. We add them both for clarity. +static PyGetSetDef SbkObjectType_Type_getsetlist[] = { + {const_cast<char*>("__signature__"), (getter)Sbk_TypeGet___signature__}, + {const_cast<char*>("__doc__"), (getter)Sbk_TypeGet___doc__}, + {nullptr} // Sentinel +}; + static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_dealloc, (void *)SbkObjectTypeDealloc}, {Py_tp_setattro, (void *)PyObject_GenericSetAttr}, {Py_tp_base, (void *)&PyType_Type}, {Py_tp_alloc, (void *)PyType_GenericAlloc}, + {Py_tp_getset, (void *)SbkObjectType_Type_getsetlist}, {Py_tp_new, (void *)SbkObjectTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, {0, 0} diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index c83f90d64..8003f142a 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -1180,4 +1180,24 @@ SetError_Argument(PyObject *args, const char *func_name) PyErr_SetObject(err, msg); } +/* + * Support for the metatype SbkObjectType_Type's tp_getset. + * + * This was not necessary for __signature__, because PyType_Type inherited it. + * But the __doc__ attribute existed already by inheritance, and calling + * PyType_Modified() is not supported. So we added the getsets explicitly + * to the metatype. + */ + +PyObject * +Sbk_TypeGet___signature__(PyObject *ob, const char *modifier) +{ + return pyside_tp_get___signature__(ob, modifier); +} + +PyObject *Sbk_TypeGet___doc__(PyObject *ob) +{ + return pyside_tp_get___doc__(ob); +} + } //extern "C" diff --git a/sources/shiboken2/libshiboken/signature.h b/sources/shiboken2/libshiboken/signature.h index 6b477c52e..57fd4047a 100644 --- a/sources/shiboken2/libshiboken/signature.h +++ b/sources/shiboken2/libshiboken/signature.h @@ -48,6 +48,8 @@ extern "C" LIBSHIBOKEN_API int SbkSpecial_Type_Ready(PyObject *, PyTypeObject *, const char *[]); LIBSHIBOKEN_API void FinishSignatureInitialization(PyObject *, const char *[]); LIBSHIBOKEN_API void SetError_Argument(PyObject *, const char *); +LIBSHIBOKEN_API PyObject *Sbk_TypeGet___signature__(PyObject *, const char *); +LIBSHIBOKEN_API PyObject *Sbk_TypeGet___doc__(PyObject *); } // extern "C" |