diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-08-31 14:38:13 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-08-31 14:38:13 +0200 |
commit | 404f584d6ac4b94c65d60aa1171f0ef1fe4dc6bd (patch) | |
tree | 84a7908dc888bc4c0c473c92c27f42bc287032f5 | |
parent | b49e0a9d9c6ba831b3931f1b6ebf1f9ed8f52962 (diff) | |
parent | 9a37b64bbee7573578f63334b76a3eca533ea539 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Icf4b3535be52b64ef15eced7103bb1280e031e30
20 files changed, 187 insertions, 121 deletions
diff --git a/build_scripts/config.py b/build_scripts/config.py index ae09ed8a3..92f1e5cab 100644 --- a/build_scripts/config.py +++ b/build_scripts/config.py @@ -92,6 +92,7 @@ class Config(object): 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ] self.setup_script_dir = None @@ -134,7 +135,7 @@ class Config(object): setup_kwargs['zip_safe'] = False setup_kwargs['cmdclass'] = cmd_class_dict setup_kwargs['version'] = package_version - setup_kwargs['python_requires'] = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.9" + setup_kwargs['python_requires'] = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.10" if quiet: diff --git a/build_scripts/wheel_override.py b/build_scripts/wheel_override.py index 03c9c92ab..298287429 100644 --- a/build_scripts/wheel_override.py +++ b/build_scripts/wheel_override.py @@ -89,7 +89,7 @@ class PysideBuildWheel(_bdist_wheel): # create a properly named package. limited_api_enabled = OPTION["LIMITED_API"] and sys.version_info[0] >= 3 if limited_api_enabled: - self.py_limited_api = "cp35.cp36.cp37.cp38" + self.py_limited_api = "cp35.cp36.cp37.cp38.cp39" _bdist_wheel.finalize_options(self) diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.py b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.py index 55805e469..089c434e5 100644 --- a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.py +++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.py @@ -2,7 +2,7 @@ ############################################################################ ## ## Copyright (C) 2013 Riverbank Computing Limited. -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2020 The Qt Company Ltd. ## Contact: http://www.qt.io/licensing/ ## ## This file is part of the Qt for Python examples of the Qt Toolkit. @@ -57,97 +57,98 @@ class MainWindow(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) - self.highlighter = Highlighter() + self._highlighter = Highlighter() - self.setupFileMenu() - self.setupEditor() + self.setup_file_menu() + self.setup_editor() - self.setCentralWidget(self.editor) + self.setCentralWidget(self._editor) self.setWindowTitle(self.tr("Syntax Highlighter")) - def newFile(self): - self.editor.clear() + def new_file(self): + self._editor.clear() - def openFile(self, path = ""): - fileName = path + def open_file(self, path=""): + file_name = path - if not fileName: - fileName, _ = QFileDialog.getOpenFileName(self, self.tr("Open File"), "", - "qmake Files (*.pro *.prf *.pri)") + if not file_name: + file_name, _ = QFileDialog.getOpenFileName(self, self.tr("Open File"), "", + "qmake Files (*.pro *.prf *.pri)") - if fileName: - inFile = QFile(fileName) + if file_name: + inFile = QFile(file_name) if inFile.open(QFile.ReadOnly | QFile.Text): stream = QTextStream(inFile) - self.editor.setPlainText(stream.readAll()) + self._editor.setPlainText(stream.readAll()) - def setupEditor(self): - variableFormat = QTextCharFormat() - variableFormat.setFontWeight(QFont.Bold) - variableFormat.setForeground(Qt.blue) - self.highlighter.addMapping("\\b[A-Z_]+\\b", variableFormat) + def setup_editor(self): + variable_format = QTextCharFormat() + variable_format.setFontWeight(QFont.Bold) + variable_format.setForeground(Qt.blue) + self._highlighter.add_mapping("\\b[A-Z_]+\\b", variable_format) - singleLineCommentFormat = QTextCharFormat() - singleLineCommentFormat.setBackground(QColor("#77ff77")) - self.highlighter.addMapping("#[^\n]*", singleLineCommentFormat) + single_line_comment_format = QTextCharFormat() + single_line_comment_format.setBackground(QColor("#77ff77")) + self._highlighter.add_mapping("#[^\n]*", single_line_comment_format) - quotationFormat = QTextCharFormat() - quotationFormat.setBackground(Qt.cyan) - quotationFormat.setForeground(Qt.blue) - self.highlighter.addMapping("\".*\"", quotationFormat) + quotation_format = QTextCharFormat() + quotation_format.setBackground(Qt.cyan) + quotation_format.setForeground(Qt.blue) + self._highlighter.add_mapping("\".*\"", quotation_format) - functionFormat = QTextCharFormat() - functionFormat.setFontItalic(True) - functionFormat.setForeground(Qt.blue) - self.highlighter.addMapping("\\b[a-z0-9_]+\\(.*\\)", functionFormat) + function_format = QTextCharFormat() + function_format.setFontItalic(True) + function_format.setForeground(Qt.blue) + self._highlighter.add_mapping("\\b[a-z0-9_]+\\(.*\\)", function_format) font = QFont() font.setFamily("Courier") font.setFixedPitch(True) font.setPointSize(10) - self.editor = QPlainTextEdit() - self.editor.setFont(font) - self.highlighter.setDocument(self.editor.document()) + self._editor = QPlainTextEdit() + self._editor.setFont(font) + self._highlighter.setDocument(self._editor.document()) - def setupFileMenu(self): - fileMenu = self.menuBar().addMenu(self.tr("&File")) + def setup_file_menu(self): + file_menu = self.menuBar().addMenu(self.tr("&File")) - newFileAct = fileMenu.addAction(self.tr("&New...")) - newFileAct.setShortcut(QKeySequence(QKeySequence.New)) - newFileAct.triggered.connect(self.newFile) + new_file_act = file_menu.addAction(self.tr("&New...")) + new_file_act.setShortcut(QKeySequence(QKeySequence.New)) + new_file_act.triggered.connect(self.new_file) - openFileAct = fileMenu.addAction(self.tr("&Open...")) - openFileAct.setShortcut(QKeySequence(QKeySequence.Open)) - openFileAct.triggered.connect(self.openFile) + open_file_act = file_menu.addAction(self.tr("&Open...")) + open_file_act.setShortcut(QKeySequence(QKeySequence.Open)) + open_file_act.triggered.connect(self.open_file) - quitAct = fileMenu.addAction(self.tr("E&xit")) - quitAct.setShortcut(QKeySequence(QKeySequence.Quit)) - quitAct.triggered.connect(self.close) + quit_act = file_menu.addAction(self.tr("E&xit")) + quit_act.setShortcut(QKeySequence(QKeySequence.Quit)) + quit_act.triggered.connect(self.close) - helpMenu = self.menuBar().addMenu("&Help") - helpMenu.addAction("About &Qt", qApp.aboutQt) + help_menu = self.menuBar().addMenu("&Help") + help_menu.addAction("About &Qt", qApp.aboutQt) class Highlighter(QSyntaxHighlighter): def __init__(self, parent=None): QSyntaxHighlighter.__init__(self, parent) - self.mappings = {} + self._mappings = {} - def addMapping(self, pattern, format): - self.mappings[pattern] = format + def add_mapping(self, pattern, format): + self._mappings[pattern] = format def highlightBlock(self, text): - for pattern in self.mappings: - for m in re.finditer(pattern,text): - s,e = m.span() - self.setFormat(s, e - s, self.mappings[pattern]) + for pattern, format in self._mappings.items(): + for match in re.finditer(pattern, text): + start, end = match.span() + self.setFormat(start, end - start, format) + if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() window.resize(640, 512) window.show() - window.openFile(":/examples/example") + window.open_file(":/examples/example") sys.exit(app.exec_()) diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py index af9f4d4f5..d71ee338e 100644 --- a/sources/pyside2/PySide2/support/generate_pyi.py +++ b/sources/pyside2/PySide2/support/generate_pyi.py @@ -171,7 +171,7 @@ class Formatter(Writer): yield @contextmanager - def function(self, func_name, signature, modifier=None): + def function(self, func_name, signature): if self.after_enum() or func_name == "__init__": self.print() key = func_name @@ -179,16 +179,16 @@ class Formatter(Writer): if type(signature) == type([]): for sig in signature: self.print('{spaces}@typing.overload'.format(**locals())) - self._function(func_name, sig, modifier, spaces) + self._function(func_name, sig, spaces) else: - self._function(func_name, signature, modifier, spaces) + self._function(func_name, signature, spaces) if func_name == "__init__": self.print() yield key - def _function(self, func_name, signature, modifier, spaces): - if modifier: - self.print('{spaces}@{modifier}'.format(**locals())) + def _function(self, func_name, signature, spaces): + if "self" not in tuple(signature.parameters.keys()): + self.print('{spaces}@staticmethod'.format(**locals())) signature = self.optional_replacer(signature) self.print('{spaces}def {func_name}{signature}: ...'.format(**locals())) diff --git a/sources/pyside2/doc/_themes/pysidedocs/static/pyside.css b/sources/pyside2/doc/_themes/pysidedocs/static/pyside.css index c6a0c56a1..f6a1c5ae4 100644 --- a/sources/pyside2/doc/_themes/pysidedocs/static/pyside.css +++ b/sources/pyside2/doc/_themes/pysidedocs/static/pyside.css @@ -552,6 +552,9 @@ tt.descname { .container { padding:0 2% } + .sphinxsidebar { + top: 16px !important; + } } #navbar .navbar-oneQt { display:inline; @@ -1172,7 +1175,9 @@ div.multi-column div { .col-2 h2,.toc h3,.sidebar-content h2, .sidebar-content h3,.sectionlist h2, .sphinxsidebar { - position: fixed; + position: -webkit-sticky; + position: sticky; + top: 64px; overflow: scroll; overflow-x: hidden; overflow-y: hidden; diff --git a/sources/pyside2/libpyside/pysidesignal.cpp b/sources/pyside2/libpyside/pysidesignal.cpp index f11f5a12d..367f85fff 100644 --- a/sources/pyside2/libpyside/pysidesignal.cpp +++ b/sources/pyside2/libpyside/pysidesignal.cpp @@ -360,7 +360,7 @@ PyObject *signalInstanceConnect(PyObject *self, PyObject *args, PyObject *kwds) if (isMethod || isFunction) { PyObject *function = isMethod ? PyMethod_GET_FUNCTION(slot) : slot; - PyCodeObject *objCode = reinterpret_cast<PyCodeObject *>(PyFunction_GET_CODE(function)); + auto *objCode = reinterpret_cast<PepCodeObject *>(PyFunction_GET_CODE(function)); useSelf = isMethod; slotArgs = PepCode_GET_FLAGS(objCode) & CO_VARARGS ? -1 : PepCode_GET_ARGCOUNT(objCode); if (useSelf) @@ -567,7 +567,11 @@ PyObject *signalCall(PyObject *self, PyObject *args, PyObject *kw) Shiboken::AutoDecRef homonymousMethod(getDescriptor(signal->homonymousMethod, 0, 0)); if (PyCFunction_Check(homonymousMethod) && (PyCFunction_GET_FLAGS(homonymousMethod.object()) & METH_STATIC)) { +#if PY_VERSION_HEX >= 0x03090000 + return PyObject_Call(homonymousMethod, args, kw); +#else return PyCFunction_Call(homonymousMethod, args, kw); +#endif } // Assumes homonymousMethod is not a static method. @@ -585,7 +589,11 @@ PyObject *signalInstanceCall(PyObject *self, PyObject *args, PyObject *kw) descrgetfunc getDescriptor = Py_TYPE(PySideSignal->d->homonymousMethod)->tp_descr_get; Shiboken::AutoDecRef homonymousMethod(getDescriptor(PySideSignal->d->homonymousMethod, PySideSignal->d->source, 0)); +#if PY_VERSION_HEX >= 0x03090000 + return PyObject_Call(homonymousMethod, args, kw); +#else return PyCFunction_Call(homonymousMethod, args, kw); +#endif } static PyObject *metaSignalCheck(PyObject * /* klass */, PyObject *arg) @@ -929,7 +937,7 @@ QString getCallbackSignature(const char *signal, QObject *receiver, PyObject *ca if (isMethod || isFunction) { PyObject *function = isMethod ? PyMethod_GET_FUNCTION(callback) : callback; - auto objCode = reinterpret_cast<PyCodeObject *>(PyFunction_GET_CODE(function)); + auto objCode = reinterpret_cast<PepCodeObject *>(PyFunction_GET_CODE(function)); functionName = Shiboken::String::toCString(PepFunction_GetName(function)); useSelf = isMethod; numArgs = PepCode_GET_FLAGS(objCode) & CO_VARARGS ? -1 : PepCode_GET_ARGCOUNT(objCode); diff --git a/sources/shiboken2/doc/_themes/pysidedocs/static/pyside.css b/sources/shiboken2/doc/_themes/pysidedocs/static/pyside.css index c6a0c56a1..f6a1c5ae4 100644 --- a/sources/shiboken2/doc/_themes/pysidedocs/static/pyside.css +++ b/sources/shiboken2/doc/_themes/pysidedocs/static/pyside.css @@ -552,6 +552,9 @@ tt.descname { .container { padding:0 2% } + .sphinxsidebar { + top: 16px !important; + } } #navbar .navbar-oneQt { display:inline; @@ -1172,7 +1175,9 @@ div.multi-column div { .col-2 h2,.toc h3,.sidebar-content h2, .sidebar-content h3,.sectionlist h2, .sphinxsidebar { - position: fixed; + position: -webkit-sticky; + position: sticky; + top: 64px; overflow: scroll; overflow-x: hidden; overflow-y: hidden; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 260607479..73f1a10cf 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -4683,6 +4683,10 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction for (const AbstractMetaFunction *f : overloads) { QStringList args; + // PYSIDE-1328: `self`-ness cannot be computed in Python because there are mixed cases. + // Toplevel functions like `PySide2.QtCore.QEnum` are always self-less. + if (!(f->isStatic()) && f->ownerClass()) + args << QLatin1String("self"); const AbstractMetaArgumentList &arguments = f->arguments(); for (const AbstractMetaArgument *arg : arguments) { QString strArg = arg->type()->pythonSignature(); diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index c3c16cb02..961c6c739 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -99,12 +99,38 @@ static SelectableFeatureHook SelectFeatureSet = nullptr; static PyObject *Sbk_TypeGet___dict__(PyTypeObject *type, void *context); // forward +static int +check_set_special_type_attr(PyTypeObject *type, PyObject *value, const char *name) +{ + if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { + PyErr_Format(PyExc_TypeError, + "can't set %s.%s", type->tp_name, name); + return 0; + } + if (!value) { + PyErr_Format(PyExc_TypeError, + "can't delete %s.%s", type->tp_name, name); + return 0; + } + return 1; +} + +// PYSIDE-1177: Add a setter to allow setting type doc. +static int +type_set_doc(PyTypeObject *type, PyObject *value, void *context) +{ + if (!check_set_special_type_attr(type, value, "__doc__")) + return -1; + PyType_Modified(type); + return PyDict_SetItem(type->tp_dict, Shiboken::PyMagicName::doc(), value); +} + // 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__}, + {const_cast<char *>("__doc__"), (getter)Sbk_TypeGet___doc__, (setter)type_set_doc}, {const_cast<char *>("__dict__"), (getter)Sbk_TypeGet___dict__}, {nullptr} // Sentinel }; @@ -881,7 +907,9 @@ void init() Conversions::init(); +#if PY_VERSION_HEX < 0x03070000 PyEval_InitThreads(); +#endif //Init private data Pep384_Init(); diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index 57d3de261..6e4926370 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -319,9 +319,9 @@ Pep_GetVerboseFlag() #ifdef Py_LIMITED_API int -PepCode_Get(PyCodeObject *co, const char *name) +PepCode_Get(PepCodeObject *co, const char *name) { - PyObject *ob = (PyObject *)co; + PyObject *ob = reinterpret_cast<PyObject *>(co); PyObject *ob_ret; int ret = -1; diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h index 973cf06ce..4b3e32ea2 100644 --- a/sources/shiboken2/libshiboken/pep384impl.h +++ b/sources/shiboken2/libshiboken/pep384impl.h @@ -327,7 +327,7 @@ LIBSHIBOKEN_API PyObject *PyRun_String(const char *, int, PyObject *, PyObject * // But this is no problem as we check it's validity for every version. #define PYTHON_BUFFER_VERSION_COMPATIBLE (PY_VERSION_HEX >= 0x03030000 && \ - PY_VERSION_HEX < 0x0308FFFF) + PY_VERSION_HEX < 0x0309FFFF) #if !PYTHON_BUFFER_VERSION_COMPATIBLE # error Please check the buffer compatibility for this python version! #endif @@ -411,23 +411,27 @@ LIBSHIBOKEN_API PyObject *PyMethod_Self(PyObject *); /* Bytecode object */ // we have to grab the code object from python -typedef struct _code PyCodeObject; +typedef struct _code PepCodeObject; -LIBSHIBOKEN_API int PepCode_Get(PyCodeObject *co, const char *name); +LIBSHIBOKEN_API int PepCode_Get(PepCodeObject *co, const char *name); -#define PepCode_GET_FLAGS(o) PepCode_Get(o, "co_flags") -#define PepCode_GET_ARGCOUNT(o) PepCode_Get(o, "co_argcount") +# define PepCode_GET_FLAGS(o) PepCode_Get(o, "co_flags") +# define PepCode_GET_ARGCOUNT(o) PepCode_Get(o, "co_argcount") /* Masks for co_flags above */ -#define CO_OPTIMIZED 0x0001 -#define CO_NEWLOCALS 0x0002 -#define CO_VARARGS 0x0004 -#define CO_VARKEYWORDS 0x0008 -#define CO_NESTED 0x0010 -#define CO_GENERATOR 0x0020 +# define CO_OPTIMIZED 0x0001 +# define CO_NEWLOCALS 0x0002 +# define CO_VARARGS 0x0004 +# define CO_VARKEYWORDS 0x0008 +# define CO_NESTED 0x0010 +# define CO_GENERATOR 0x0020 + #else -#define PepCode_GET_FLAGS(o) ((o)->co_flags) -#define PepCode_GET_ARGCOUNT(o) ((o)->co_argcount) + +# define PepCodeObject PyCodeObject +# define PepCode_GET_FLAGS(o) ((o)->co_flags) +# define PepCode_GET_ARGCOUNT(o) ((o)->co_argcount) + #endif /***************************************************************************** diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp index 9dd98eef3..602c0619b 100644 --- a/sources/shiboken2/libshiboken/sbkstaticstrings.cpp +++ b/sources/shiboken2/libshiboken/sbkstaticstrings.cpp @@ -78,8 +78,10 @@ namespace PyMagicName { // exported: STATIC_STRING_IMPL(class_, "__class__") STATIC_STRING_IMPL(dict, "__dict__") +STATIC_STRING_IMPL(doc, "__doc__") STATIC_STRING_IMPL(ecf, "__ecf__") STATIC_STRING_IMPL(file, "__file__") +STATIC_STRING_IMPL(get, "__get__") STATIC_STRING_IMPL(members, "__members__") STATIC_STRING_IMPL(module, "__module__") STATIC_STRING_IMPL(name, "__name__") diff --git a/sources/shiboken2/libshiboken/sbkstaticstrings.h b/sources/shiboken2/libshiboken/sbkstaticstrings.h index ebb64579c..df0c683b0 100644 --- a/sources/shiboken2/libshiboken/sbkstaticstrings.h +++ b/sources/shiboken2/libshiboken/sbkstaticstrings.h @@ -64,8 +64,10 @@ namespace PyMagicName { LIBSHIBOKEN_API PyObject *class_(); LIBSHIBOKEN_API PyObject *dict(); +LIBSHIBOKEN_API PyObject *doc(); LIBSHIBOKEN_API PyObject *ecf(); LIBSHIBOKEN_API PyObject *file(); +LIBSHIBOKEN_API PyObject *get(); LIBSHIBOKEN_API PyObject *members(); LIBSHIBOKEN_API PyObject *module(); LIBSHIBOKEN_API PyObject *name(); diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index e4dc27ea7..e2c02a196 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -731,8 +731,9 @@ handle_doc(PyObject *ob, PyObject *old_descr) name = reinterpret_cast<PyTypeObject *>(ob_type_mod.object())->tp_name; if (handle_doc_in_progress || name == nullptr || strncmp(name, "PySide2.", 8) != 0) - return PyObject_CallMethod(old_descr, const_cast<char *>("__get__"), - const_cast<char *>("(O)"), ob); + return PyObject_CallMethodObjArgs(old_descr, + Shiboken::PyMagicName::get(), + ob, nullptr); handle_doc_in_progress++; PyObject *res = PyObject_CallFunction( pyside_globals->make_helptext_func, diff --git a/sources/shiboken2/libshiboken/threadstatesaver.cpp b/sources/shiboken2/libshiboken/threadstatesaver.cpp index 0d19528f9..085535fd7 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.cpp +++ b/sources/shiboken2/libshiboken/threadstatesaver.cpp @@ -51,7 +51,11 @@ ThreadStateSaver::~ThreadStateSaver() void ThreadStateSaver::save() { +#if PY_VERSION_HEX >= 0x0309000 + if (Py_IsInitialized()) +#else if (PyEval_ThreadsInitialized()) +#endif m_threadState = PyEval_SaveThread(); } diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py index 384273d92..51ce60bfa 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py @@ -231,17 +231,14 @@ def create_signature(props, key): # this is the basic layout of a signature varnames = props["varnames"] if layout.definition: - if sig_kind == "function": - pass - elif sig_kind == "method": - varnames = ("self",) + varnames - elif sig_kind == "staticmethod": - pass - elif sig_kind == "classmethod": - varnames = ("klass",) + varnames - else: - raise SystemError("Methods must be function, method, staticmethod" - " or classmethod") + # PYSIDE-1328: We no longer use info from the sig_kind which is + # more complex for multiple signatures. We now get `self` from the + # parser. + pass + else: + if "self" in varnames[:1]: + varnames = varnames[1:] + # calculate the modifications defaults = props["defaults"][:] if not layout.defaults: @@ -259,6 +256,8 @@ def create_signature(props, key): elif name.startswith("*"): kind = _VAR_POSITIONAL ann = annotations.get(name, _empty) + if ann == "self": + ann = _empty name = name.lstrip("*") defpos = idx - len(varnames) + len(defaults) default = defaults[defpos] if defpos >= 0 else _empty 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 fa4d5e77c..371b3ca4a 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 @@ -154,14 +154,11 @@ class ExactEnumerator(object): self.fmt.class_name = class_name ret.update(self.function("__init__", klass)) for func_name, func in functions: - func_kind = get_signature(func, "__func_kind__") - modifier = func_kind if func_kind in ( - "staticmethod", "classmethod") else None - ret.update(self.function(func_name, func, modifier)) + ret.update(self.function(func_name, func)) self.fmt.level -= 1 return ret - def function(self, func_name, func, modifier=None): + def function(self, func_name, func): self.fmt.level += 1 ret = self.result_type() signature = func.__signature__ @@ -192,7 +189,7 @@ class SimplifyingEnumerator(ExactEnumerator): is desired. """ - def function(self, func_name, func, modifier=None): + def function(self, func_name, func): ret = self.result_type() signature = get_signature(func, 'existence') sig = stringify(signature) if signature is not None else None @@ -209,11 +206,11 @@ class HintingEnumerator(ExactEnumerator): hinting stubs. Only default values are replaced by "...". """ - def function(self, func_name, func, modifier=None): + def function(self, func_name, func): ret = self.result_type() signature = get_signature(func, 'hintingstub') if signature is not None: - with self.fmt.function(func_name, signature, modifier) as key: + with self.fmt.function(func_name, signature) as key: ret[key] = signature return ret diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 71a78cd3e..24107cfed 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -349,6 +349,11 @@ type_map.update({ "QStringList*" : ResultVariable(StringList), }) +# PYSIDE-1328: We need to handle "self" explicitly. +type_map.update({ + "self" : "self", + }) + # The Shiboken Part def init_Shiboken(): diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py index bfc5b3a30..9dd7608b3 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -110,22 +110,25 @@ def _parse_line(line): argstr = ret.arglist.replace("->", ".deref.") arglist = _parse_arglist(argstr) args = [] - for arg in arglist: + for idx, arg in enumerate(arglist): tokens = arg.split(":") if len(tokens) < 2: - warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line)) - else: - name, ann = tokens - if name in keyword.kwlist: - if LIST_KEYWORDS: - print("KEYWORD", ret) - name = name + "_" - if "=" in ann: - ann, default = ann.split("=", 1) - tup = name, ann, default + if idx == 0 and tokens[0] == "self": + tokens = 2 * tokens # "self: self" else: - tup = name, ann - args.append(tup) + warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line)) + continue + name, ann = tokens + if name in keyword.kwlist: + if LIST_KEYWORDS: + print("KEYWORD", ret) + name = name + "_" + if "=" in ann: + ann, default = ann.split("=", 1) + tup = name, ann, default + else: + tup = name, ann + args.append(tup) ret.arglist = args multi = ret.multi if multi is not None: diff --git a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py index 532f2226c..9ce641f61 100644 --- a/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken2/tests/samplebinding/pointerprimitivetype_test.py @@ -70,10 +70,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): self.assertTrue(found) ann = sig.parameters["data"].annotation self.assertEqual(ann.__args__, (int,)) - # un-specify this class (forget "int") by setting the _special - # flag, so we can check using issubclass (undocumented feature). - ann._special = True - self.assertTrue(issubclass(ann, typing.Iterable)) + self.assertTrue(issubclass(ann.__origin__, typing.Iterable)) def testReturnVarSignature(self): # signature="getMargins(int*,int*,int*,int*)const"> |