Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/5.12' into 5.13
Browse files Browse the repository at this point in the history
Change-Id: Ic2c43ef80769e3063dac771518c803861510f72e
  • Loading branch information
ablasche committed Jul 18, 2019
2 parents 97718de + 295d9d7 commit 4646b86
Show file tree
Hide file tree
Showing 57 changed files with 773 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ develop-eggs/
downloads/
eggs/
.eggs/
lib/
/lib/
lib64/
parts/
sdist/
Expand Down
3 changes: 2 additions & 1 deletion coin_test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def call_testrunner(python_ver, buildnro):
_pExe, _env, env_pip, env_python = get_qtci_virtualEnv(python_ver, CI_HOST_OS, CI_HOST_ARCH, CI_TARGET_ARCH)
rmtree(_env, True)
run_instruction(["virtualenv", "-p", _pExe, _env], "Failed to create virtualenv")
install_pip_dependencies(env_pip, ["pip", "numpy", "PyOpenGL", "setuptools", "six", "pyinstaller", "wheel"])
# Keeping PyInstaller 3.4, because 3.5 seems to have broken our test
install_pip_dependencies(env_pip, ["pip", "numpy", "PyOpenGL", "setuptools", "six", "pyinstaller==3.4", "wheel"])
cmd = [env_python, "testrunner.py", "test",
"--blacklist", "build_history/blacklist.txt",
"--buildno=" + buildnro]
Expand Down
11 changes: 6 additions & 5 deletions sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2514,11 +2514,12 @@
<define-ownership class="target" owner="default"/>
</modify-argument>
</modify-function>
<modify-function signature="value(const QString&amp;,const QVariant&amp;)const">
<inject-documentation mode="append" format="target">
.. warning:: QSettings.value can return different types (QVariant types) depending on the platform it's running on, so the safest way to use it is always casting the result to the desired type, e.g.: int(settings.value("myKey"))
</inject-documentation>
</modify-function>
<!-- PYSIDE-1010:
We remove the original implementation of value() to include the optional parameter -->
<modify-function signature="value(const QString&amp;,const QVariant&amp;)const" remove="all"/>
<add-function signature="value(const QString&amp;, const QVariant&amp; @defaultValue@ = 0, PyObject* @type@ = 0)" return-type="PyObject*">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qsettings-value"/>
</add-function>
</object-type>
<object-type name="QEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::None">
<enum-type name="Type"/>
Expand Down
50 changes: 50 additions & 0 deletions sources/pyside2/PySide2/glue/qtcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,56 @@ bool py2kStrCheck(PyObject *obj)
}
// @snippet pystring-check

// @snippet qsettings-value
QVariant out = %CPPSELF.value(%1, %2);
PyTypeObject *typeObj = reinterpret_cast<PyTypeObject*>(%PYARG_3);

if (typeObj) {
if (typeObj == &PyList_Type) {
QByteArrayList valuesList = out.toByteArray().split(',');
const int valuesSize = valuesList.size();
if (valuesSize > 0) {
PyObject *list = PyList_New(valuesSize);
for (int i = 0; i < valuesSize; i++) {
PyObject *item = PyUnicode_FromString(valuesList[i].data());
PyList_SET_ITEM(list, i, item);
Py_DECREF(item);
}
%PYARG_0 = list;

} else {
%PYARG_0 = %CONVERTTOPYTHON[QVariant](out);
}
} else if (typeObj == &PyBytes_Type) {
QByteArray asByteArray = out.toByteArray();
%PYARG_0 = PyBytes_FromString(asByteArray.data());
} else if (typeObj == &PyUnicode_Type) {
QByteArray asByteArray = out.toByteArray();
%PYARG_0 = PyUnicode_FromString(asByteArray.data());
#ifdef IS_PY3K
} else if (typeObj == &PyLong_Type) {
float asFloat = out.toFloat();
pyResult = PyLong_FromDouble(asFloat);
#else
} else if (typeObj == &PyInt_Type) {
float asFloat = out.toFloat();
pyResult = PyInt_FromLong(long(asFloat));
#endif
} else if (typeObj == &PyFloat_Type) {
float asFloat = out.toFloat();
%PYARG_0 = PyFloat_FromDouble(asFloat);
}
// TODO: PyDict_Type and PyTuple_Type
}
else {
if (out == 0)
%PYARG_0 = Py_None;
else
%PYARG_0 = %CONVERTTOPYTHON[QVariant](out);
}

// @snippet qsettings-value

// @snippet qvariant-conversion
static const char *QVariant_resolveMetaType(PyTypeObject *type, int *typeId)
{
Expand Down
4 changes: 4 additions & 0 deletions sources/pyside2/PySide2/support/generate_pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def generate_all_pyi(outpath, options):
from PySide2.support.signature import inspect
from PySide2.support.signature.lib.enum_sig import HintingEnumerator

# propagate USE_PEP563 to the mapping module.
# Perhaps this can be automated?
PySide2.support.signature.mapping.USE_PEP563 = USE_PEP563

outpath = outpath or os.path.dirname(PySide2.__file__)
name_list = PySide2.__all__ if options.modules == ["all"] else options.modules
errors = ", ".join(set(name_list) - set(PySide2.__all__))
Expand Down
1 change: 1 addition & 0 deletions sources/pyside2/tests/QtCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ PYSIDE_TEST(qrect_test.py)
PYSIDE_TEST(qregexp_test.py)
PYSIDE_TEST(qregularexpression_test.py)
PYSIDE_TEST(qresource_test.py)
PYSIDE_TEST(qsettings_test.py)
PYSIDE_TEST(qsize_test.py)
PYSIDE_TEST(qslot_object_test.py)
PYSIDE_TEST(qsocketnotifier_test.py)
Expand Down
4 changes: 4 additions & 0 deletions sources/pyside2/tests/QtCore/qsettings_test.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[General]
var1=a, b, c
var2=a

77 changes: 77 additions & 0 deletions sources/pyside2/tests/QtCore/qsettings_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#############################################################################
##
## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the test suite of Qt for Python.
##
## $QT_BEGIN_LICENSE:GPL-EXCEPT$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see https://www.qt.io/terms-conditions. For further
## information use the contact form at https://www.qt.io/contact-us.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3 as published by the Free Software
## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
## included in the packaging of this file. Please review the following
## information to ensure the GNU General Public License requirements will
## be met: https://www.gnu.org/licenses/gpl-3.0.html.
##
## $QT_END_LICENSE$
##
#############################################################################

'''Test cases for QDate'''

import unittest

import os
from helper import adjust_filename
import py3kcompat as py3k
from PySide2.QtCore import QSettings

class TestQSettings(unittest.TestCase):
def testConversions(self):
file_path = adjust_filename('qsettings_test.ini', __file__)
settings = QSettings(file_path, QSettings.IniFormat)

r = settings.value('var1')
self.assertEqual(type(r), list)

r = settings.value('var2')
if py3k.IS_PY3K:
self.assertEqual(type(r), str)
else:
self.assertEqual(type(r), unicode)

r = settings.value('var2', type=list)
self.assertEqual(type(r), list)


def testDefaultValueConversion(self):
settings = QSettings('foo.ini', QSettings.IniFormat)
r = settings.value('lala', 22)
if py3k.IS_PY3K:
self.assertEqual(type(r), int)
else:
self.assertEqual(type(r), long)

r = settings.value('lala', 22, type=str)
self.assertEqual(type(r), str)

r = settings.value('lala', 22, type=bytes)
self.assertEqual(type(r), bytes)

r = settings.value('lala', 22, type=int)
self.assertEqual(type(r), int)

r = settings.value('lala', 22, type=float)
self.assertEqual(type(r), float)

if __name__ == '__main__':
unittest.main()
Empty file modified sources/pyside2/tests/QtQml/CMakeLists.txt
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_1029.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_1029.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_451.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_451.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_456.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_456.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_557.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_726.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_726.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_814.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_814.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_825.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_825.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_847.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_847.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_915.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_926.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_926.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_951.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_951.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_995.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_995.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_997.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/bug_997.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/connect_python_qml.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/hw.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/qqmlnetwork_test.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/qquickview_test.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/registertype.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/registertype.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/signal_arguments.py
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/view.qml
100755 → 100644
Empty file.
Empty file modified sources/pyside2/tests/QtQml/viewmodel.qml
100755 → 100644
Empty file.
4 changes: 4 additions & 0 deletions sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem
reason = AbstractMetaBuilder::GenerationDisabled;
}
if (reason != AbstractMetaBuilder::NoReason) {
if (fullClassName.isEmpty()) {
QTextStream(&fullClassName) << "anonymous struct at " << classItem->fileName()
<< ':' << classItem->startLine();
}
m_rejectedClasses.insert(fullClassName, reason);
return nullptr;
}
Expand Down
17 changes: 17 additions & 0 deletions sources/shiboken2/ApiExtractor/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ QString msgCannotUseEnumAsInt(const QString &name)
"Compilation errors may occur when used as a function argument.");
}

QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType)
{
QString result;
QTextStream str(&result);
str << "Types of receiver variable ('" << varType
<< "') and %%CONVERTTOCPP type system variable ('" << conversionType
<< "') differ";
QString strippedVarType = varType;
QString strippedConversionType = conversionType;
TypeInfo::stripQualifiers(&strippedVarType);
TypeInfo::stripQualifiers(&strippedConversionType);
if (strippedVarType == strippedConversionType)
str << " in qualifiers. Please make sure the type is a distinct token";
str << '.';
return result;
}

// main.cpp

QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs)
Expand Down
2 changes: 2 additions & 0 deletions sources/shiboken2/ApiExtractor/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ QString msgCannotOpenForWriting(const QFile &f);

QString msgCannotUseEnumAsInt(const QString &name);

QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType);

QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs);

QString msgInvalidVersion(const QString &package, const QString &version);
Expand Down
1 change: 1 addition & 0 deletions sources/shiboken2/ApiExtractor/parser/codemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class _CodeModelItem
FileModelItem file() const;

void getStartPosition(int *line, int *column);
int startLine() const { return m_startLine; }
void setStartPosition(int line, int column);

void getEndPosition(int *line, int *column);
Expand Down
23 changes: 23 additions & 0 deletions sources/shiboken2/doc/typesystemvariables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ Variables
Replaced by a |project| conversion call that converts a Python variable
to a C++ variable of the type indicated by ``CPPTYPE``.

Typically, this is a variable assignment:

.. code-block:: c++

double value = %CONVERTTOCPP[double](pyValue);

Pointer assignments are also possible:

.. code-block:: c++

void f(double *valuePtr)
{
*valuePtr = %CONVERTTOCPP[double](pyValue);
Note however, that for variable definitions, the type must
be a space-delimited token:

.. code-block:: c++

double * valuePtr = %CONVERTTOCPP[double](pyValue);

since it otherwise would be indistinguishable from the pointer assignment
above.

.. _converttopython:

Expand Down
10 changes: 7 additions & 3 deletions sources/shiboken2/generator/shiboken2/cppgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3032,18 +3032,21 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe
s << INDENT << "if (kwds) {" << endl;
{
Indentation indent(INDENT);
s << INDENT << "PyObject *";
s << INDENT << "PyObject *keyName = nullptr;" << endl;
s << INDENT << "PyObject *value = nullptr;" << endl;
for (const AbstractMetaArgument *arg : args) {
int pyArgIndex = arg->argumentIndex() - OverloadData::numberOfRemovedArguments(func, arg->argumentIndex());
QString pyArgName = usePyArgs ? pythonArgsAt(pyArgIndex) : QLatin1String(PYTHON_ARG);
s << "value = PyDict_GetItemString(kwds, \"" << arg->name() << "\");" << endl;
s << INDENT << "keyName = Py_BuildValue(\"s\",\"" << arg->name() << "\");" << endl;
s << INDENT << "if (PyDict_Contains(kwds, keyName)) {" << endl;
s << INDENT << "value = PyDict_GetItemString(kwds, \"" << arg->name() << "\");" << endl;
s << INDENT << "if (value && " << pyArgName << ") {" << endl;
{
Indentation indent(INDENT);
s << INDENT << pyErrString.arg(arg->name()) << endl;
s << INDENT << returnStatement(m_currentErrorCode) << endl;
}
s << INDENT << "} else if (value) {" << endl;
s << INDENT << INDENT << "} else if (value) {" << endl;
{
Indentation indent(INDENT);
s << INDENT << pyArgName << " = value;" << endl;
Expand All @@ -3058,6 +3061,7 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe
s << INDENT << '}' << endl;
if (arg != args.constLast())
s << INDENT;
s << "}" << endl;
}
}
s << INDENT << '}' << endl;
Expand Down
9 changes: 5 additions & 4 deletions sources/shiboken2/generator/shiboken2/shibokengenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ ShibokenGenerator::ShibokenGenerator()
const char CHECKTYPE_REGEX[] = R"(%CHECKTYPE\[([^\[]*)\]\()";
const char ISCONVERTIBLE_REGEX[] = R"(%ISCONVERTIBLE\[([^\[]*)\]\()";
const char CONVERTTOPYTHON_REGEX[] = R"(%CONVERTTOPYTHON\[([^\[]*)\]\()";
// Capture a '*' leading the variable name into the target
// so that "*valuePtr = %CONVERTTOCPP..." works as expected.
const char CONVERTTOCPP_REGEX[] =
R"((\*?%?[a-zA-Z_][\w\.]*(?:\[[^\[^<^>]+\])*)(?:\s+)=(?:\s+)%CONVERTTOCPP\[([^\[]*)\]\()";
m_typeSystemConvRegEx[TypeSystemCheckFunction] = QRegularExpression(QLatin1String(CHECKTYPE_REGEX));
Expand Down Expand Up @@ -2044,10 +2046,9 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa
varType = miniNormalizer(varType);
QString varName = list.at(1).trimmed();
if (!varType.isEmpty()) {
if (varType != conversionType->cppSignature()) {
qFatal("Types of receiver variable ('%s') and %%CONVERTTOCPP type system variable ('%s') differ.",
qPrintable(varType), qPrintable(conversionType->cppSignature()));
}
const QString conversionSignature = conversionType->cppSignature();
if (varType != conversionSignature)
qFatal("%s", qPrintable(msgConversionTypesDiffer(varType, conversionSignature)));
c << getFullTypeName(conversionType) << ' ' << varName;
writeMinimalConstructorExpression(c, conversionType);
c << ';' << endl;
Expand Down
2 changes: 2 additions & 0 deletions sources/shiboken2/shibokenmodule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/
"${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/__init__.py" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py"
"${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/tool.py"
"${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/tool.py" COPYONLY)
if (PYTHON_VERSION_MAJOR EQUAL 3)
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/backport_inspect.py"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,7 @@
from textwrap import dedent
from shibokensupport.signature import inspect
from shibokensupport.signature.mapping import ellipsis


class SimpleNamespace(object):
# From types.rst, because the builtin is implemented in Python 3, only.
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def __repr__(self):
keys = sorted(self.__dict__)
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
return "{}({})".format(type(self).__name__, ", ".join(items))

def __eq__(self, other):
return self.__dict__ == other.__dict__
from shibokensupport.signature.lib.tool import SimpleNamespace


class SignatureLayout(SimpleNamespace):
Expand Down
Loading

0 comments on commit 4646b86

Please sign in to comment.