diff options
Diffstat (limited to 'sources/shiboken2')
15 files changed, 305 insertions, 46 deletions
diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt index de6bf019f..f8e504583 100644 --- a/sources/shiboken2/ApiExtractor/CMakeLists.txt +++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt @@ -84,7 +84,7 @@ endif() target_compile_definitions(apiextractor PRIVATE CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}") -set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) +set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) if (BUILD_TESTS) find_package(Qt${QT_MAJOR_VERSION}Test 5.12 REQUIRED) diff --git a/sources/shiboken2/generator/CMakeLists.txt b/sources/shiboken2/generator/CMakeLists.txt index e311d400e..1a3f4e5c4 100644 --- a/sources/shiboken2/generator/CMakeLists.txt +++ b/sources/shiboken2/generator/CMakeLists.txt @@ -30,7 +30,7 @@ configure_file(shibokenconfig.h.in "${CMAKE_CURRENT_BINARY_DIR}/shibokenconfig.h install(TARGETS shiboken2 EXPORT Shiboken2Targets - DESTINATION bin) + DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") set(shiboken_generator_package_name "shiboken2_generator") diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index 5543427fc..443d25cdf 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -104,6 +104,23 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = { {nullptr} // Sentinel }; +#if PY_VERSION_HEX < 0x03000000 + +static PyObject *SbkObjectType_repr(PyObject *type) +{ + Shiboken::AutoDecRef mod(PyObject_GetAttr(type, Shiboken::PyMagicName::module())); + if (mod.isNull()) + return nullptr; + Shiboken::AutoDecRef name(PyObject_GetAttr(type, Shiboken::PyMagicName::qualname())); + if (name.isNull()) + return nullptr; + return PyString_FromFormat("<class '%s.%s'>", + PyString_AS_STRING(mod.object()), + PyString_AS_STRING(name.object())); +} + +#endif // PY_VERSION_HEX < 0x03000000 + static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectTypeDealloc)}, {Py_tp_setattro, reinterpret_cast<void *>(PyObject_GenericSetAttr)}, @@ -112,6 +129,9 @@ static PyType_Slot SbkObjectType_Type_slots[] = { {Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)}, {Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)}, {Py_tp_getset, reinterpret_cast<void *>(SbkObjectType_Type_getsetlist)}, +#if PY_VERSION_HEX < 0x03000000 + {Py_tp_repr, reinterpret_cast<void *>(SbkObjectType_repr)}, +#endif {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { @@ -633,11 +653,42 @@ PyObject *SbkType_FromSpec(PyType_Spec *spec) PyObject *SbkType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { + // PYSIDE-1286: Generate correct __module__ and __qualname__ + // The name field can now be extended by an "n:" prefix which is + // the number of modules in the name. The default is 1. + // + // Example: + // "2:mainmod.submod.mainclass.subclass" + // results in + // __module__ : "mainmod.submod" + // __qualname__ : "mainclass.subclass" + // __name__ : "subclass" + PyType_Spec new_spec = *spec; const char *colon = strchr(spec->name, ':'); assert(colon); - new_spec.name = colon + 1; - return PyType_FromSpecWithBases(&new_spec, bases); + int package_level = atoi(spec->name); + const char *mod = new_spec.name = colon + 1; + + PyObject *type = PyType_FromSpecWithBases(&new_spec, bases); + if (type == nullptr) + return nullptr; + + const char *qual = mod; + for (int idx = package_level; idx > 0; --idx) { + const char *dot = strchr(qual, '.'); + if (!dot) + break; + qual = dot + 1; + } + int mlen = qual - mod - 1; + Shiboken::AutoDecRef module(Shiboken::String::fromCString(mod, mlen)); + Shiboken::AutoDecRef qualname(Shiboken::String::fromCString(qual)); + if (PyObject_SetAttr(type, Shiboken::PyMagicName::module(), module) < 0) + return nullptr; + if (PyObject_SetAttr(type, Shiboken::PyMagicName::qualname(), qualname) < 0) + return nullptr; + return type; } } //extern "C" diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index c04848eb3..f07cac613 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -638,6 +638,38 @@ PepType_GetNameStr(PyTypeObject *type) /***************************************************************************** * + * Newly introduced convenience functions + * + */ +#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) + +PyObject * +PyImport_GetModule(PyObject *name) +{ + PyObject *m; + PyObject *modules = PyImport_GetModuleDict(); + if (modules == NULL) { + PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); + return NULL; + } + Py_INCREF(modules); + if (PyDict_CheckExact(modules)) { + m = PyDict_GetItemWithError(modules, name); /* borrowed */ + Py_XINCREF(m); + } + else { + m = PyObject_GetItem(modules, name); + if (m == NULL && PyErr_ExceptionMatches(PyExc_KeyError)) { + PyErr_Clear(); + } + } + Py_DECREF(modules); + return m; +} + +#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) +/***************************************************************************** + * * Extra support for name mangling * */ diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h index e735095e8..541b0e775 100644 --- a/sources/shiboken2/libshiboken/pep384impl.h +++ b/sources/shiboken2/libshiboken/pep384impl.h @@ -523,6 +523,16 @@ extern LIBSHIBOKEN_API PyTypeObject *PepMethodDescr_TypePtr; /***************************************************************************** * + * Newly introduced convenience functions + * + * This is not defined if Py_LIMITED_API is defined. + */ +#if PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) +LIBSHIBOKEN_API PyObject *PyImport_GetModule(PyObject *name); +#endif // PY_VERSION_HEX < 0x03070000 || defined(Py_LIMITED_API) + +/***************************************************************************** + * * Runtime support for Python 3.8 incompatibilities * */ diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index f49623440..36f2f48f9 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -107,16 +107,18 @@ static PyObject *SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) if (!self) return nullptr; self->ob_value = itemValue; - PyObject *item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); - if (item) { - self->ob_name = SbkEnumObject_name(item, nullptr); - Py_XDECREF(item); - } else { - self->ob_name = nullptr; - } + Shiboken::AutoDecRef item(Shiboken::Enum::getEnumItemFromValue(type, itemValue)); + self->ob_name = item.object() ? SbkEnumObject_name(item, nullptr) : nullptr; return reinterpret_cast<PyObject *>(self); } +void enum_object_dealloc(PyObject *ob) +{ + auto self = reinterpret_cast<SbkEnumObject *>(ob); + Py_XDECREF(self->ob_name); + Sbk_object_dealloc(ob); +} + static PyObject *enum_op(enum_func f, PyObject *a, PyObject *b) { PyObject *valA = a; PyObject *valB = b; @@ -260,6 +262,23 @@ static PyGetSetDef SbkEnumGetSetList[] = { {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; +#if PY_VERSION_HEX < 0x03000000 + +static PyObject *SbkEnumType_repr(PyObject *type) +{ + Shiboken::AutoDecRef mod(PyObject_GetAttr(type, Shiboken::PyMagicName::module())); + if (mod.isNull()) + return nullptr; + Shiboken::AutoDecRef name(PyObject_GetAttr(type, Shiboken::PyMagicName::qualname())); + if (name.isNull()) + return nullptr; + return PyString_FromFormat("<class '%s.%s'>", + PyString_AS_STRING(mod.object()), + PyString_AS_STRING(name.object())); +} + +#endif // PY_VERSION_HEX < 0x03000000 + static void SbkEnumTypeDealloc(PyObject *pyObj); static PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds); @@ -287,6 +306,9 @@ static PyType_Slot SbkEnumType_Type_slots[] = { {Py_tp_alloc, (void *)PyType_GenericAlloc}, {Py_tp_new, (void *)SbkEnumTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, +#if PY_VERSION_HEX < 0x03000000 + {Py_tp_repr, (void *)SbkEnumType_repr}, +#endif {0, nullptr} }; static PyType_Spec SbkEnumType_Type_spec = { @@ -341,6 +363,107 @@ PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwd } // extern "C" +/////////////////////////////////////////////////////////////// +// +// PYSIDE-15: Pickling Support for Qt Enum objects +// This works very well and fixes the issue. +// +extern "C" { + +static void init_enum(); // forward + +static PyObject *enum_unpickler = nullptr; + +// Pickling: reduce the Qt Enum object +static PyObject *enum___reduce__(PyObject *obj) +{ + init_enum(); + return Py_BuildValue("O(Ni)", + enum_unpickler, + Py_BuildValue("s", Py_TYPE(obj)->tp_name), + PyInt_AS_LONG(obj)); +} + +} // extern "C" + +namespace Shiboken { namespace Enum { + +// Unpickling: rebuild the Qt Enum object +PyObject *unpickleEnum(PyObject *enum_class_name, PyObject *value) +{ + Shiboken::AutoDecRef parts(PyObject_CallMethod(enum_class_name, + const_cast<char *>("split"), const_cast<char *>("s"), ".")); + if (parts.isNull()) + return nullptr; + PyObject *top_name = PyList_GetItem(parts, 0); // borrowed ref + if (top_name == nullptr) + return nullptr; + PyObject *module = PyImport_GetModule(top_name); + if (module == nullptr) { + PyErr_Format(PyExc_ImportError, "could not import module %.200s", + Shiboken::String::toCString(top_name)); + return nullptr; + } + Shiboken::AutoDecRef cur_thing(module); + int len = PyList_Size(parts); + for (int idx = 1; idx < len; ++idx) { + PyObject *name = PyList_GetItem(parts, idx); // borrowed ref + PyObject *thing = PyObject_GetAttr(cur_thing, name); + if (thing == nullptr) { + PyErr_Format(PyExc_ImportError, "could not import Qt Enum type %.200s", + Shiboken::String::toCString(enum_class_name)); + return nullptr; + } + cur_thing.reset(thing); + } + PyObject *klass = cur_thing; + return PyObject_CallFunctionObjArgs(klass, value, nullptr); +} + +} // namespace Enum +} // namespace Shiboken + +extern "C" { + +// Initialization +static bool _init_enum() +{ + static PyObject *shiboken_name = Py_BuildValue("s", "shiboken2"); + if (shiboken_name == nullptr) + return false; + Shiboken::AutoDecRef shibo(PyImport_GetModule(shiboken_name)); + if (shibo.isNull()) + return false; + Shiboken::AutoDecRef sub(PyObject_GetAttr(shibo, shiboken_name)); + PyObject *mod = sub.object(); + if (mod == nullptr) { + // We are in the build dir and already in shiboken. + PyErr_Clear(); + mod = shibo.object(); + } + enum_unpickler = PyObject_GetAttrString(mod, "_unpickle_enum"); + if (enum_unpickler == nullptr) + return false; + return true; +} + +static void init_enum() +{ + if (!(enum_unpickler || _init_enum())) + Py_FatalError("could not load enum pickling helper function"); +} + +static PyMethodDef SbkEnumObject_Methods[] = { + {const_cast<char *>("__reduce__"), reinterpret_cast<PyCFunction>(enum___reduce__), + METH_NOARGS, nullptr}, + {nullptr, nullptr, 0, nullptr} // Sentinel +}; + +} // extern "C" + +// +/////////////////////////////////////////////////////////////// + namespace Shiboken { class DeclaredEnumTypes @@ -376,7 +499,7 @@ PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) while (PyDict_Next(values, &pos, &key, &value)) { auto *obj = reinterpret_cast<SbkEnumObject *>(value); if (obj->ob_value == itemValue) { - Py_INCREF(obj); + Py_INCREF(value); return value; } } @@ -501,6 +624,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_tp_repr, (void *)SbkEnumObject_repr}, {Py_tp_str, (void *)SbkEnumObject_repr}, {Py_tp_getset, (void *)SbkEnumGetSetList}, + {Py_tp_methods, (void *)SbkEnumObject_Methods}, {Py_tp_new, (void *)SbkEnum_tp_new}, {Py_nb_add, (void *)enum_add}, {Py_nb_subtract, (void *)enum_subtract}, @@ -522,7 +646,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_nb_index, (void *)enum_int}, {Py_tp_richcompare, (void *)enum_richcompare}, {Py_tp_hash, (void *)enum_hash}, - {Py_tp_dealloc, (void *)Sbk_object_dealloc}, + {Py_tp_dealloc, (void *)enum_object_dealloc}, {0, nullptr} }; static PyType_Spec SbkNewType_spec = { @@ -613,7 +737,6 @@ newTypeWithName(const char *name, newspec->slots = newslots; auto *type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(newspec)); Py_TYPE(type) = SbkEnumType_TypeF(); - Py_INCREF(Py_TYPE(type)); auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; diff --git a/sources/shiboken2/libshiboken/sbkenum.h b/sources/shiboken2/libshiboken/sbkenum.h index 759d72636..c294c17d9 100644 --- a/sources/shiboken2/libshiboken/sbkenum.h +++ b/sources/shiboken2/libshiboken/sbkenum.h @@ -114,6 +114,8 @@ namespace Enum LIBSHIBOKEN_API void setTypeConverter(PyTypeObject *enumType, SbkConverter *converter); /// Returns the converter assigned to the enum \p type. LIBSHIBOKEN_API SbkConverter *getTypeConverter(PyTypeObject *enumType); + + LIBSHIBOKEN_API PyObject *unpickleEnum(PyObject *, PyObject *); } } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 5430ab064..ba1fc119e 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -39,6 +39,7 @@ #include "basewrapper.h" #include "autodecref.h" +#include "sbkstring.h" #include "sbkstaticstrings.h" #include "sbkstaticstrings_p.h" @@ -185,7 +186,6 @@ _get_class_of_sm(PyObject *ob_sm) static PyObject * _get_class_of_descr(PyObject *ob) { - Shiboken::AutoDecRef func_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); return PyObject_GetAttr(ob, Shiboken::PyMagicName::objclass()); } @@ -318,6 +318,20 @@ pyside_tp_get___signature__(PyObject *obtype_mod, PyObject *modifier) static PyObject * GetSignature_Cached(PyObject *props, PyObject *func_kind, PyObject *modifier); +// Helper for __qualname__ which might not always exist in Python 2 (type). +static PyObject * +_get_qualname(PyObject *ob) +{ + // We support __qualname__ for types, only. + assert(PyType_Check(ob)); + PyObject *name = PyObject_GetAttr(ob, Shiboken::PyMagicName::qualname()); + if (name == nullptr) { + PyErr_Clear(); + name = PyObject_GetAttr(ob, Shiboken::PyMagicName::name()); + } + return name; +} + static PyObject * GetTypeKey(PyObject *ob) { @@ -334,19 +348,20 @@ GetTypeKey(PyObject *ob) * * This is the PyCFunction behavior, as opposed to Python functions. */ - Shiboken::AutoDecRef class_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); + // PYSIDE-1286: We use correct __module__ and __qualname__, now. Shiboken::AutoDecRef module_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::module())); - - if (module_name.isNull()) + if (module_name.isNull()) { + // We have no module_name because this is a module ;-) PyErr_Clear(); - - // Note: if we have a module, then __module__ is null, and we get - // the module name through __name__ . - if (class_name.isNull()) + module_name.reset(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); + return Py_BuildValue("O", module_name.object()); + } + Shiboken::AutoDecRef class_name(_get_qualname(ob)); + if (class_name.isNull()) { + Py_FatalError("Signature: missing class name in GetTypeKey"); return nullptr; - if (module_name.object()) - return Py_BuildValue("(OO)", module_name.object(), class_name.object()); - return Py_BuildValue("O", class_name.object()); + } + return Py_BuildValue("(OO)", module_name.object(), class_name.object()); } static PyObject *empty_dict = nullptr; @@ -402,7 +417,6 @@ GetSignature_Wrapper(PyObject *ob, PyObject *modifier) Shiboken::AutoDecRef func_name(PyObject_GetAttr(ob, Shiboken::PyMagicName::name())); Shiboken::AutoDecRef objclass(PyObject_GetAttr(ob, Shiboken::PyMagicName::objclass())); Shiboken::AutoDecRef class_key(GetTypeKey(objclass)); - if (func_name.isNull() || objclass.isNull() || class_key.isNull()) return nullptr; PyObject *dict = TypeKey_to_PropsDict(class_key, objclass); @@ -851,12 +865,15 @@ get_signature(PyObject * /* self */, PyObject *args) //////////////////////////////////////////////////////////////////////////// // a stack trace for linux-like platforms #include <stdio.h> -#include <execinfo.h> +#if defined(__GLIBC__) +# include <execinfo.h> +#endif #include <signal.h> #include <stdlib.h> #include <unistd.h> void handler(int sig) { +#if defined(__GLIBC__) void *array[30]; size_t size; @@ -864,8 +881,11 @@ void handler(int sig) { size = backtrace(array, 30); // print out all the frames to stderr +#endif fprintf(stderr, "Error: signal %d:\n", sig); +#if defined(__GLIBC__) backtrace_symbols_fd(array, size, STDERR_FILENO); +#endif exit(1); } diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py index 1f6d70b31..0f9598c64 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/backport_inspect.py @@ -109,8 +109,13 @@ CO_NOFREE = 0x0040 ############################################################################### + +# PYSIDE-1286: We now use the added __qualname__ for classes. +def _get_class_name(cls): + return getattr(cls, "__qualname__", cls.__name__) + # This function was changed: 'builtins' and 'qualname' don't exist. -# We use '__builtin__' and '__name__' instead. +# We use '__builtin__' and '__(qual)?name__' instead. def formatannotation(annotation, base_module=None): if getattr(annotation, '__module__', None) == 'typing': # The replace must not be done on Python 2.7 because it @@ -118,8 +123,8 @@ def formatannotation(annotation, base_module=None): return repr(annotation) ##.replace('typing.', '') if isinstance(annotation, type): if annotation.__module__ in ('__builtin__', base_module): - return annotation.__name__ - return annotation.__module__+'.'+annotation.__name__ + return _get_class_name(annotation) + return annotation.__module__ + '.' + _get_class_name(annotation) return repr(annotation) @@ -393,7 +398,7 @@ class Parameter(object): return formatted def __repr__(self): - return '<{} "{}">'.format(self.__class__.__name__, self) + return '<{} "{}">'.format(_get_class_name(self.__class__), self) def __hash__(self): return hash((self.name, self.kind, self.annotation, self.default)) @@ -536,7 +541,7 @@ class BoundArguments(object): args = [] for arg, value in self.arguments.items(): args.append('{}={!r}'.format(arg, value)) - return '<{} ({})>'.format(self.__class__.__name__, ', '.join(args)) + return '<{} ({})>'.format(_get_class_name(self.__class__), ', '.join(args)) class Signature(object): @@ -842,7 +847,7 @@ class Signature(object): self._return_annotation = state['_return_annotation'] def __repr__(self): - return '<{} {}>'.format(self.__class__.__name__, self) + return '<{} {}>'.format(_get_class_name(self.__class__), self) def __str__(self): result = [] diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py index 0403358bb..4dbed077d 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2019 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py index 0417f132a..7af43bea0 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/importhandler.py @@ -70,7 +70,7 @@ def finish_import(module): if func: func(module) except Exception as e: - name = e.__class__.__name__ + name = e.__class__.__qualname__ print(72 * "*") print("Error in deprecated.py, ignored:") print(" {name}: {e}".format(**locals())) diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py index f11f3cf3d..fa4d5e77c 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2018 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of Qt for Python. @@ -100,17 +100,19 @@ class ExactEnumerator(object): return ret def klass(self, class_name, klass): + ret = self.result_type() + if "<" in class_name: + # This is happening in QtQuick for some reason: + ## class QSharedPointer<QQuickItemGrabResult >: + # We simply skip over this class. + return ret bases_list = [] for base in klass.__bases__: name = base.__name__ - if name in ("object", "type"): - pass - else: - modname = base.__module__ - name = modname + "." + base.__name__ + if name not in ("object", "type"): + name = base.__module__ + "." + name bases_list.append(name) class_str = "{}({})".format(class_name, ", ".join(bases_list)) - ret = self.result_type() # class_members = inspect.getmembers(klass) # gives us also the inherited things. class_members = sorted(list(klass.__dict__.items())) diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 8d970956b..2053c3e9d 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -165,6 +165,11 @@ def try_to_guess(thing, valtype): return ret return None +def get_name(thing): + if isinstance(thing, type): + return getattr(thing, "__qualname__", thing.__name__) + else: + return thing.__name__ def _resolve_value(thing, valtype, line): if thing in ("0", "None") and valtype: @@ -172,7 +177,7 @@ def _resolve_value(thing, valtype, line): return None map = type_map[valtype] # typing.Any: '_SpecialForm' object has no attribute '__name__' - name = map.__name__ if hasattr(map, "__name__") else str(map) + name = get_name(map) if hasattr(map, "__name__") else str(map) thing = "zero({})".format(name) if thing in type_map: return type_map[thing] @@ -212,7 +217,8 @@ def to_string(thing): return thing if hasattr(thing, "__name__"): dot = "." in str(thing) - return thing.__module__ + "." + thing.__name__ if dot else thing.__name__ + name = get_name(thing) + return thing.__module__ + "." + name if dot else name # Note: This captures things from the typing module: return str(thing) diff --git a/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml index bdb0c9338..3eba557fb 100644 --- a/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml +++ b/sources/shiboken2/shibokenmodule/typesystem_shiboken.xml @@ -103,6 +103,12 @@ </inject-code> </add-function> + <add-function signature="_unpickle_enum(PyObject*, PyObject*)" return-type="PyObject*"> + <inject-code> + %PYARG_0 = Shiboken::Enum::unpickleEnum(%1, %2); + </inject-code> + </add-function> + <extra-includes> <include file-name="sbkversion.h" location="local"/> <include file-name="voidptr.h" location="local"/> diff --git a/sources/shiboken2/tests/shiboken_test_helper.py b/sources/shiboken2/tests/shiboken_test_helper.py index 2564c91d4..793baf4ad 100644 --- a/sources/shiboken2/tests/shiboken_test_helper.py +++ b/sources/shiboken2/tests/shiboken_test_helper.py @@ -31,8 +31,10 @@ def objectFullname(t): + # '__qualname__' for Python 2 does exist for PySide types, only. + name = getattr(t, "__qualname__", t.__name__) module = t.__module__ if module is None or module == str.__class__.__module__: - return t.__name__ + return name else: - return module + '.' + t.__name__ + return module + '.' + name |