From 01b43dc3d93e632c3c42fb8e1105f200b9cee2ae Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Tue, 13 Aug 2019 11:15:52 +0200 Subject: Add QtCore.Slot.__signature__ and much more manually The signature of QtCore.Slot and other classes could not automatically be generated because the function is not generated by cppgenerator.cpp . We add it manually in the C++ code into the generation process. The case of QtCore.Slot had diverse follow-up issues to be solved: - Classes which did not inherit from Shiboken were not generated. This is a long-standing omission and creates very many new simple types. - The arity of Slot has default arguments after the varargs parameter "*types". This needed an extended Python parser analysis that fixes the arguments given to the inspect module, accordingly. - The signature generation was completely new implemented and relies no longer on the restricted syntax of a Python (2) function but generates signatures directly as Parameter instances. Implemented classes with hand-made signatures: QtCore.ClassInfo QtCore.MetaFunction, QtCore.MetaSignal QtCore.Property QtCore.Signal QtCore.SignalInstance QtCore.Slot QtQml.ListProperty QtQml.VolatileBool As a side effect, many more subtypes were published. Enums are done, which concludes this work. Fixes: PYSIDE-945 Fixes: PYSIDE-1052 Change-Id: Ic09f02ece3a90325519e42e4e39719beb0c27ae9 Reviewed-by: Christian Tismer --- sources/pyside2/libpyside/pysideslot.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'sources/pyside2/libpyside/pysideslot.cpp') diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index 2f8e69e8f..204253aa2 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -45,8 +45,7 @@ #include #include - -#define SLOT_DEC_NAME "Slot" +#include struct SlotData { @@ -76,7 +75,7 @@ static PyType_Slot PySideSlotType_slots[] = { {0, 0} }; static PyType_Spec PySideSlotType_spec = { - "PySide2.QtCore." SLOT_DEC_NAME, + "PySide2.QtCore.Slot", sizeof(PySideSlot), 0, Py_TPFLAGS_DEFAULT, @@ -102,7 +101,7 @@ int slotTpInit(PyObject *self, PyObject *args, PyObject *kw) if (emptyTuple == 0) emptyTuple = PyTuple_New(0); - if (!PyArg_ParseTupleAndKeywords(emptyTuple, kw, "|sO:QtCore." SLOT_DEC_NAME, + if (!PyArg_ParseTupleAndKeywords(emptyTuple, kw, "|sO:QtCore.Slot", const_cast(kwlist), &argName, &argResult)) { return -1; } @@ -177,15 +176,20 @@ PyObject *slotCall(PyObject *self, PyObject *args, PyObject * /* kw */) } // extern "C" -namespace PySide { namespace Slot { +namespace PySide { +namespace Slot { + +static const char *Slot_SignatureStrings[] = { + "PySide2.QtCore.Slot(*types:type,name:str=nullptr,result:str=nullptr)->typing.Callable[...,typing.Optional[str]]", + nullptr}; // Sentinel void init(PyObject *module) { - if (PyType_Ready(PySideSlotTypeF()) < 0) + if (SbkSpecial_Type_Ready(module, PySideSlotTypeF(), Slot_SignatureStrings) < 0) return; Py_INCREF(PySideSlotTypeF()); - PyModule_AddObject(module, SLOT_DEC_NAME, reinterpret_cast(PySideSlotTypeF())); + PyModule_AddObject(module, "Slot", reinterpret_cast(PySideSlotTypeF())); } } // namespace Slot -- cgit v1.2.3