From d6b81b6303957803582d0fae95a9b25483d8e7f2 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Mon, 4 May 2020 17:38:04 +0200 Subject: shiboken: Prepare for introduction of __qualname__ To remove the groundwork from the next checkin, the step of replacing PyType_FromSpec with SbkType_FromSpec is extracted. This change introduces a packageLevel number that is generated as a name prefix in the class creation but does not use it, yet. Change-Id: Ic9061231708b546dbd3620d148bca24c27df60a5 Task-number: PYSIDE-1286 Reviewed-by: Friedemann Kleint --- .../PySide2/QtQml/pysideqmlregistertype.cpp | 11 ++++--- sources/pyside2/libpyside/pysideclassinfo.cpp | 4 +-- sources/pyside2/libpyside/pysidemetafunction.cpp | 7 ++--- sources/pyside2/libpyside/pysideproperty.cpp | 9 +++--- sources/pyside2/libpyside/pysideqflags.cpp | 4 +-- sources/pyside2/libpyside/pysidesignal.cpp | 14 ++++----- sources/pyside2/libpyside/pysideslot.cpp | 7 ++--- sources/pyside2/libpyside/pysideweakref.cpp | 4 +-- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 9 ++++-- sources/shiboken2/libshiboken/basewrapper.cpp | 34 +++++++++++++++------- sources/shiboken2/libshiboken/basewrapper.h | 4 +++ sources/shiboken2/libshiboken/sbkenum.cpp | 10 +++---- sources/shiboken2/libshiboken/sbkstaticstrings.cpp | 1 + sources/shiboken2/libshiboken/sbkstaticstrings.h | 1 + sources/shiboken2/libshiboken/voidptr.cpp | 15 +++++----- .../files.dir/shibokensupport/signature/loader.py | 8 +++-- .../files.dir/shibokensupport/typing27.py | 7 ++--- 17 files changed, 84 insertions(+), 65 deletions(-) diff --git a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp index fb9a5a0cf..efc86a048 100644 --- a/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp +++ b/sources/pyside2/PySide2/QtQml/pysideqmlregistertype.cpp @@ -240,7 +240,7 @@ static PyType_Slot PropertyListType_slots[] = { {0, 0} }; static PyType_Spec PropertyListType_spec = { - "PySide2.QtQml.ListProperty", + "2:PySide2.QtQml.ListProperty", sizeof(PySideProperty), 0, Py_TPFLAGS_DEFAULT, @@ -253,7 +253,7 @@ PyTypeObject *PropertyListTypeF(void) static PyTypeObject *type = nullptr; if (!type) { PyObject *bases = Py_BuildValue("(O)", PySidePropertyTypeF()); - type = (PyTypeObject *)PyType_FromSpecWithBases(&PropertyListType_spec, bases); + type = (PyTypeObject *)SbkType_FromSpecWithBases(&PropertyListType_spec, bases); Py_XDECREF(bases); } return type; @@ -454,7 +454,7 @@ static PyType_Slot QtQml_VolatileBoolType_slots[] = { {0, 0} }; static PyType_Spec QtQml_VolatileBoolType_spec = { - "PySide2.QtQml.VolatileBool", + "2:PySide2.QtQml.VolatileBool", sizeof(QtQml_VolatileBoolObject), 0, Py_TPFLAGS_DEFAULT, @@ -464,9 +464,8 @@ static PyType_Spec QtQml_VolatileBoolType_spec = { PyTypeObject *QtQml_VolatileBoolTypeF(void) { - static PyTypeObject *type = nullptr; - if (!type) - type = (PyTypeObject *)PyType_FromSpec(&QtQml_VolatileBoolType_spec); + static PyTypeObject *type = reinterpret_cast( + SbkType_FromSpec(&QtQml_VolatileBoolType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysideclassinfo.cpp b/sources/pyside2/libpyside/pysideclassinfo.cpp index c4bace77e..375a31b57 100644 --- a/sources/pyside2/libpyside/pysideclassinfo.cpp +++ b/sources/pyside2/libpyside/pysideclassinfo.cpp @@ -64,7 +64,7 @@ static PyType_Slot PySideClassInfoType_slots[] = { {0, 0} }; static PyType_Spec PySideClassInfoType_spec = { - "PySide2.QtCore.ClassInfo", + "2:PySide2.QtCore.ClassInfo", sizeof(PySideClassInfo), 0, Py_TPFLAGS_DEFAULT, @@ -75,7 +75,7 @@ static PyType_Spec PySideClassInfoType_spec = { PyTypeObject *PySideClassInfoTypeF(void) { static PyTypeObject *type = - reinterpret_cast(PyType_FromSpec(&PySideClassInfoType_spec)); + reinterpret_cast(SbkType_FromSpec(&PySideClassInfoType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysidemetafunction.cpp b/sources/pyside2/libpyside/pysidemetafunction.cpp index 637aa0598..f4b95385a 100644 --- a/sources/pyside2/libpyside/pysidemetafunction.cpp +++ b/sources/pyside2/libpyside/pysidemetafunction.cpp @@ -66,7 +66,7 @@ static PyType_Slot PySideMetaFunctionType_slots[] = { {0, 0} }; static PyType_Spec PySideMetaFunctionType_spec = { - "PySide2.QtCore.MetaFunction", + "2:PySide2.QtCore.MetaFunction", sizeof(PySideMetaFunction), 0, Py_TPFLAGS_DEFAULT, @@ -76,9 +76,8 @@ static PyType_Spec PySideMetaFunctionType_spec = { PyTypeObject *PySideMetaFunctionTypeF(void) { - static PyTypeObject *type = nullptr; - if (!type) - type = (PyTypeObject *)PyType_FromSpec(&PySideMetaFunctionType_spec); + static PyTypeObject *type = reinterpret_cast( + SbkType_FromSpec(&PySideMetaFunctionType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysideproperty.cpp b/sources/pyside2/libpyside/pysideproperty.cpp index bdabf1202..77dc6f3fc 100644 --- a/sources/pyside2/libpyside/pysideproperty.cpp +++ b/sources/pyside2/libpyside/pysideproperty.cpp @@ -88,9 +88,9 @@ static PyType_Slot PySidePropertyType_slots[] = { {Py_tp_getset, PySidePropertyType_getset}, {0, 0} }; -// Dotted modulename is crucial for PyType_FromSpec to work. Is this name right? +// Dotted modulename is crucial for SbkType_FromSpec to work. Is this name right? static PyType_Spec PySidePropertyType_spec = { - "PySide2.QtCore.Property", + "2:PySide2.QtCore.Property", sizeof(PySideProperty), 0, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE, @@ -100,9 +100,8 @@ static PyType_Spec PySidePropertyType_spec = { PyTypeObject *PySidePropertyTypeF(void) { - static PyTypeObject *type = nullptr; - if (!type) - type = (PyTypeObject *)PyType_FromSpec(&PySidePropertyType_spec); + static PyTypeObject *type = reinterpret_cast( + SbkType_FromSpec(&PySidePropertyType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysideqflags.cpp b/sources/pyside2/libpyside/pysideqflags.cpp index 8cf9aa7b2..d7e6b4f4c 100644 --- a/sources/pyside2/libpyside/pysideqflags.cpp +++ b/sources/pyside2/libpyside/pysideqflags.cpp @@ -174,7 +174,7 @@ namespace QFlags char qualname[200]; // PYSIDE-747: Here we insert now the full class name. strcpy(qualname, name); - // Careful: PyType_FromSpec does not allocate the string. + // Careful: SbkType_FromSpec does not allocate the string. PyType_Spec *newspec = new PyType_Spec; newspec->name = strdup(qualname); newspec->basicsize = SbkNewQFlagsType_spec.basicsize; @@ -186,7 +186,7 @@ namespace QFlags SbkNewQFlagsType_slots[idx].pfunc = numberMethods[idx].pfunc; } newspec->slots = SbkNewQFlagsType_spec.slots; - PyTypeObject *type = (PyTypeObject *)PyType_FromSpec(newspec); + PyTypeObject *type = (PyTypeObject *)SbkType_FromSpec(newspec); Py_TYPE(type) = &PyType_Type; PySideQFlagsType *flagsType = reinterpret_cast(type); diff --git a/sources/pyside2/libpyside/pysidesignal.cpp b/sources/pyside2/libpyside/pysidesignal.cpp index be4c367f7..0fa33254c 100644 --- a/sources/pyside2/libpyside/pysidesignal.cpp +++ b/sources/pyside2/libpyside/pysidesignal.cpp @@ -115,9 +115,9 @@ static PyType_Slot PySideMetaSignalType_slots[] = { {0, 0} }; static PyType_Spec PySideMetaSignalType_spec = { - "PySide2.QtCore.MetaSignal", + "2:PySide2.QtCore.MetaSignal", 0, - // sizeof(PyHeapTypeObject) is filled in by PyType_FromSpecWithBases + // sizeof(PyHeapTypeObject) is filled in by SbkType_FromSpecWithBases // which calls PyType_Ready which calls inherit_special. 0, Py_TPFLAGS_DEFAULT, @@ -130,7 +130,7 @@ PyTypeObject *PySideMetaSignalTypeF(void) static PyTypeObject *type = nullptr; if (!type) { PyObject *bases = Py_BuildValue("(O)", &PyType_Type); - type = (PyTypeObject *)PyType_FromSpecWithBases(&PySideMetaSignalType_spec, bases); + type = (PyTypeObject *)SbkType_FromSpecWithBases(&PySideMetaSignalType_spec, bases); Py_XDECREF(bases); } return type; @@ -147,7 +147,7 @@ static PyType_Slot PySideSignalType_slots[] = { {0, 0} }; static PyType_Spec PySideSignalType_spec = { - "PySide2.QtCore.Signal", + "2:PySide2.QtCore.Signal", sizeof(PySideSignal), 0, Py_TPFLAGS_DEFAULT, @@ -159,7 +159,7 @@ PyTypeObject *PySideSignalTypeF(void) { static PyTypeObject *type = nullptr; if (!type) { - type = (PyTypeObject *)PyType_FromSpec(&PySideSignalType_spec); + type = reinterpret_cast(SbkType_FromSpec(&PySideSignalType_spec)); PyTypeObject *hold = Py_TYPE(type); Py_TYPE(type) = PySideMetaSignalTypeF(); Py_INCREF(Py_TYPE(type)); @@ -186,7 +186,7 @@ static PyType_Slot PySideSignalInstanceType_slots[] = { {0, 0} }; static PyType_Spec PySideSignalInstanceType_spec = { - "PySide2.QtCore.SignalInstance", + "2:PySide2.QtCore.SignalInstance", sizeof(PySideSignalInstance), 0, Py_TPFLAGS_DEFAULT, @@ -197,7 +197,7 @@ static PyType_Spec PySideSignalInstanceType_spec = { PyTypeObject *PySideSignalInstanceTypeF(void) { static PyTypeObject *type = - (PyTypeObject *)PyType_FromSpec(&PySideSignalInstanceType_spec); + reinterpret_cast(SbkType_FromSpec(&PySideSignalInstanceType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysideslot.cpp b/sources/pyside2/libpyside/pysideslot.cpp index 04212a64e..e60115450 100644 --- a/sources/pyside2/libpyside/pysideslot.cpp +++ b/sources/pyside2/libpyside/pysideslot.cpp @@ -75,7 +75,7 @@ static PyType_Slot PySideSlotType_slots[] = { {0, 0} }; static PyType_Spec PySideSlotType_spec = { - "PySide2.QtCore.Slot", + "2:PySide2.QtCore.Slot", sizeof(PySideSlot), 0, Py_TPFLAGS_DEFAULT, @@ -85,9 +85,8 @@ static PyType_Spec PySideSlotType_spec = { static PyTypeObject *PySideSlotTypeF(void) { - static PyTypeObject *type = nullptr; - if (!type) - type = (PyTypeObject *)PyType_FromSpec(&PySideSlotType_spec); + static PyTypeObject *type = reinterpret_cast( + SbkType_FromSpec(&PySideSlotType_spec)); return type; } diff --git a/sources/pyside2/libpyside/pysideweakref.cpp b/sources/pyside2/libpyside/pysideweakref.cpp index faa3abe82..84b390e96 100644 --- a/sources/pyside2/libpyside/pysideweakref.cpp +++ b/sources/pyside2/libpyside/pysideweakref.cpp @@ -57,7 +57,7 @@ static PyType_Slot PySideCallableObjectType_slots[] = { {0, 0} }; static PyType_Spec PySideCallableObjectType_spec = { - const_cast("PySide.Callable"), + "1:PySide.Callable", sizeof(PySideCallableObject), 0, Py_TPFLAGS_DEFAULT, @@ -68,7 +68,7 @@ static PyType_Spec PySideCallableObjectType_spec = { static PyTypeObject *PySideCallableObjectTypeF() { static PyTypeObject *type = - (PyTypeObject *)PyType_FromSpec(&PySideCallableObjectType_spec); + reinterpret_cast(SbkType_FromSpec(&PySideCallableObjectType_spec)); return type; } diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index c0c54f274..64467e3d1 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -4037,8 +4037,10 @@ void CppGenerator::writeClassDefinition(QTextStream &s, } s << INDENT << "{0, " << NULL_PTR << "}\n"; s << "};\n"; + + int packageLevel = packageName().count(QLatin1Char('.')) + 1; s << "static PyType_Spec " << className << "_spec = {\n"; - s << INDENT << "\"" << computedClassTargetFullName << "\",\n"; + s << INDENT << '"' << packageLevel << ':' << computedClassTargetFullName << "\",\n"; s << INDENT << "sizeof(SbkObject),\n"; s << INDENT << "0,\n"; s << INDENT << tp_flags << ",\n"; @@ -4667,6 +4669,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu QString enumVarTypeObj; if (!cppEnum->isAnonymous()) { + int packageLevel = packageName().count(QLatin1Char('.')) + 1; FlagsTypeEntry *flags = enumTypeEntry->flags(); if (flags) { // The following could probably be made nicer: @@ -4674,7 +4677,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu QString fullPath = getClassTargetFullName(cppEnum); fullPath.truncate(fullPath.lastIndexOf(QLatin1Char('.')) + 1); s << INDENT << cpythonTypeNameExt(flags) << " = PySide::QFlags::create(\"" - << fullPath << flags->flagsName() << "\", " + << packageLevel << ':' << fullPath << flags->flagsName() << "\", " << cpythonEnumName(cppEnum) << "_number_slots);\n"; } @@ -4686,7 +4689,7 @@ void CppGenerator::writeEnumInitialization(QTextStream &s, const AbstractMetaEnu { Indentation indent(INDENT); s << INDENT << '"' << cppEnum->name() << "\",\n"; - s << INDENT << '"' << getClassTargetFullName(cppEnum) << "\",\n"; + s << INDENT << '"' << packageLevel << ':' << getClassTargetFullName(cppEnum) << "\",\n"; s << INDENT << '"' << (cppEnum->enclosingClass() ? (cppEnum->enclosingClass()->qualifiedCppName() + QLatin1String("::")) : QString()); s << cppEnum->name() << '"'; if (flags) diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index b0d453cc5..4612afaa5 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -44,6 +44,7 @@ #include "sbkconverter.h" #include "sbkenum.h" #include "sbkstring.h" +#include "sbkstaticstrings.h" #include "sbkstaticstrings_p.h" #include "autodecref.h" #include "gilstate.h" @@ -112,7 +113,7 @@ static PyType_Slot SbkObjectType_Type_slots[] = { {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { - "Shiboken.ObjectType", + "1:Shiboken.ObjectType", 0, // basicsize (inserted later) sizeof(PyMemberDef), Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, @@ -214,7 +215,7 @@ PyTypeObject *SbkObjectType_TypeF(void) if (!type) { SbkObjectType_Type_spec.basicsize = PepHeapType_SIZE + sizeof(SbkObjectTypePrivate); - type = reinterpret_cast(PyType_FromSpec(&SbkObjectType_Type_spec)); + type = reinterpret_cast(SbkType_FromSpec(&SbkObjectType_Type_spec)); #if PY_VERSION_HEX < 0x03000000 if (patch_tp_new_wrapper(type) < 0) return nullptr; @@ -288,7 +289,7 @@ static PyType_Slot SbkObject_Type_slots[] = { {0, nullptr} }; static PyType_Spec SbkObject_Type_spec = { - "Shiboken.Object", + "1:Shiboken.Object", sizeof(SbkObject), 0, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, @@ -300,7 +301,7 @@ SbkObjectType *SbkObject_TypeF(void) { static PyTypeObject *type = nullptr; if (!type) { - type = reinterpret_cast(PyType_FromSpec(&SbkObject_Type_spec)); + type = reinterpret_cast(SbkType_FromSpec(&SbkObject_Type_spec)); Py_TYPE(type) = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(type)); type->tp_weaklistoffset = offsetof(SbkObject, weakreflist); @@ -614,8 +615,7 @@ PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *) return self == nullptr ? nullptr : _setupNew(self, subtype); } -PyObject * -SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *) +PyObject *SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *) { // PYSIDE-595: Give the same error as type_call does when tp_new is NULL. PyErr_Format(PyExc_TypeError, @@ -624,6 +624,20 @@ SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *) return nullptr; } +PyObject *SbkType_FromSpec(PyType_Spec *spec) +{ + return SbkType_FromSpecWithBases(spec, nullptr); +} + +PyObject *SbkType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) +{ + PyType_Spec new_spec = *spec; + const char *colon = strchr(spec->name, ':'); + assert(colon); + new_spec.name = colon + 1; + return PyType_FromSpecWithBases(&new_spec, bases); +} + } //extern "C" @@ -745,13 +759,13 @@ void init() Shiboken::ObjectType::initPrivateData(SbkObject_TypeF()); if (PyType_Ready(SbkEnumType_TypeF()) < 0) - Py_FatalError("[libshiboken] Failed to initialise Shiboken.SbkEnumType metatype."); + Py_FatalError("[libshiboken] Failed to initialize Shiboken.SbkEnumType metatype."); if (PyType_Ready(SbkObjectType_TypeF()) < 0) - Py_FatalError("[libshiboken] Failed to initialise Shiboken.BaseWrapperType metatype."); + Py_FatalError("[libshiboken] Failed to initialize Shiboken.BaseWrapperType metatype."); if (PyType_Ready(reinterpret_cast(SbkObject_TypeF())) < 0) - Py_FatalError("[libshiboken] Failed to initialise Shiboken.BaseWrapper type."); + Py_FatalError("[libshiboken] Failed to initialize Shiboken.BaseWrapper type."); VoidPtr::init(); @@ -901,7 +915,7 @@ introduceWrapperType(PyObject *enclosingObject, { typeSpec->slots[0].pfunc = reinterpret_cast(baseType ? baseType : SbkObject_TypeF()); - PyObject *heaptype = PyType_FromSpecWithBases(typeSpec, baseTypes); + PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes); Py_TYPE(heaptype) = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); auto *type = reinterpret_cast(heaptype); diff --git a/sources/shiboken2/libshiboken/basewrapper.h b/sources/shiboken2/libshiboken/basewrapper.h index 813870dac..4132b5cc5 100644 --- a/sources/shiboken2/libshiboken/basewrapper.h +++ b/sources/shiboken2/libshiboken/basewrapper.h @@ -122,6 +122,10 @@ LIBSHIBOKEN_API PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *args, Py /// PYSIDE-939: Replaced by Sbk_object_dealloc. LIBSHIBOKEN_API PyObject *SbkDummyNew(PyTypeObject *type, PyObject *, PyObject *); +/// PYSIDE-1286: Generate correct __module__ and __qualname__ +LIBSHIBOKEN_API PyObject *SbkType_FromSpec(PyType_Spec *); +LIBSHIBOKEN_API PyObject *SbkType_FromSpecWithBases(PyType_Spec *, PyObject *); + } // extern "C" namespace Shiboken diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 65f63ca81..f49623440 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -290,7 +290,7 @@ static PyType_Slot SbkEnumType_Type_slots[] = { {0, nullptr} }; static PyType_Spec SbkEnumType_Type_spec = { - "Shiboken.EnumType", + "1:Shiboken.EnumType", 0, // filled in later sizeof(PyMemberDef), Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES, @@ -304,7 +304,7 @@ PyTypeObject *SbkEnumType_TypeF(void) if (!type) { SbkEnumType_Type_spec.basicsize = PepHeapType_SIZE + sizeof(SbkEnumTypePrivate); - type = (PyTypeObject *)PyType_FromSpec(&SbkEnumType_Type_spec); + type = reinterpret_cast(SbkType_FromSpec(&SbkEnumType_Type_spec)); } return type; } @@ -594,7 +594,7 @@ newTypeWithName(const char *name, const char *cppName, PyTypeObject *numbers_fromFlag) { - // Careful: PyType_FromSpec does not allocate the string. + // Careful: SbkType_FromSpec does not allocate the string. PyType_Slot newslots[99] = {}; // enough but not too big for the stack auto *newspec = new PyType_Spec; newspec->name = strdup(name); @@ -611,7 +611,7 @@ newTypeWithName(const char *name, if (numbers_fromFlag) copyNumberMethods(numbers_fromFlag, newslots, &idx); newspec->slots = newslots; - auto *type = reinterpret_cast(PyType_FromSpec(newspec)); + auto *type = reinterpret_cast(SbkType_FromSpec(newspec)); Py_TYPE(type) = SbkEnumType_TypeF(); Py_INCREF(Py_TYPE(type)); @@ -659,7 +659,7 @@ DeclaredEnumTypes::DeclaredEnumTypes() = default; DeclaredEnumTypes::~DeclaredEnumTypes() { /* - * PYSIDE-595: This was "delete *it;" before introducing 'PyType_FromSpec'. + * PYSIDE-595: This was "delete *it;" before introducing 'SbkType_FromSpec'. * XXX what should I do now? * Refcounts in tests are 30 or 0 at end. * When I add the default tp_dealloc, we get negative refcounts! diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp index 3681a093d..c19665176 100644 --- a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp +++ b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp @@ -75,6 +75,7 @@ STATIC_STRING_IMPL(ecf, "__ecf__") STATIC_STRING_IMPL(file, "__file__") STATIC_STRING_IMPL(module, "__module__") STATIC_STRING_IMPL(name, "__name__") +STATIC_STRING_IMPL(qualname, "__qualname__") // Internal: STATIC_STRING_IMPL(base, "__base__") diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.h b/sources/shiboken2/libshiboken/sbkstaticstrings.h index a951899b6..07d6cc60a 100644 --- a/sources/shiboken2/libshiboken/sbkstaticstrings.h +++ b/sources/shiboken2/libshiboken/sbkstaticstrings.h @@ -61,6 +61,7 @@ LIBSHIBOKEN_API PyObject *ecf(); LIBSHIBOKEN_API PyObject *file(); LIBSHIBOKEN_API PyObject *module(); LIBSHIBOKEN_API PyObject *name(); +LIBSHIBOKEN_API PyObject *qualname(); } // namespace PyMagicName } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp index 46f49b67e..6ac3c131d 100644 --- a/sources/shiboken2/libshiboken/voidptr.cpp +++ b/sources/shiboken2/libshiboken/voidptr.cpp @@ -340,7 +340,7 @@ static PyType_Slot SbkVoidPtrType_slots[] = { {0, nullptr} }; static PyType_Spec SbkVoidPtrType_spec = { - "shiboken2.libshiboken.VoidPtr", + "2:shiboken2.shiboken2.VoidPtr", sizeof(SbkVoidPtrObject), 0, Py_TPFLAGS_DEFAULT, @@ -353,16 +353,15 @@ static PyType_Spec SbkVoidPtrType_spec = { PyTypeObject *SbkVoidPtrTypeF(void) { static PyTypeObject *type = nullptr; - if (!type) - type = reinterpret_cast(PyType_FromSpec(&SbkVoidPtrType_spec)); - + if (!type) { + type = reinterpret_cast(SbkType_FromSpec(&SbkVoidPtrType_spec)); #if PY_VERSION_HEX < 0x03000000 - type->tp_as_buffer = &SbkVoidPtrObjectBufferProc; - type->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER; + type->tp_as_buffer = &SbkVoidPtrObjectBufferProc; + type->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER; #else - PepType_AS_BUFFER(type) = &SbkVoidPtrObjectBufferProc; + PepType_AS_BUFFER(type) = &SbkVoidPtrObjectBufferProc; #endif - + } return type; } diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py index 6564786b9..1efc6fde5 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py @@ -75,14 +75,18 @@ try: except NameError: ModuleNotFoundError = ImportError +def _qualname(x): + return getattr(x, "__qualname__", x.__name__) + # patching inspect's formatting to keep the word "typing": def formatannotation(annotation, base_module=None): # if getattr(annotation, '__module__', None) == 'typing': # return repr(annotation).replace('typing.', '') if isinstance(annotation, type): + name = _qualname(annotation) if annotation.__module__ in ('builtins', base_module): - return annotation.__qualname__ - return annotation.__module__ + '.' + annotation.__qualname__ + return name + return annotation.__module__ + '.' + name return repr(annotation) # Note also that during the tests we have a different encoding that would diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/typing27.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/typing27.py index 44d78c433..41ed456cc 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/typing27.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/typing27.py @@ -184,11 +184,8 @@ __all__ = [ def _qualname(x): - if sys.version_info[:2] >= (3, 3): - return x.__qualname__ - else: - # Fall back to just name. - return x.__name__ + # PYSIDE-1286: Support __qualname__ in Python 2 + return getattr(x, "__qualname__", x.__name__) def _trim_name(nm): -- cgit v1.2.3