diff options
| author | Brett Stottlemyer <bstottle@ford.com> | 2021-07-03 15:46:02 -0400 |
|---|---|---|
| committer | Brett Stottlemyer <bstottle@ford.com> | 2021-07-29 04:17:54 -0400 |
| commit | 71d8ac47106b82d8b507d5004c0dda8156c5eb91 (patch) | |
| tree | e14b08db1b713feada0b7afef21059d350b22a23 /sources/pyside6/libpyside/pysideclassinfo.cpp | |
| parent | 45a8fafb9c445ebcdea125b0c20cd14dc42784d1 (diff) | |
Allow spaces in ClassInfo keys
Qt Remote Objects uses ClassInfo keys with spaces. Because PySide uses
keyword arguments for keys in the ClassInfo() decorator, it is not possible
to create the QtRO info from PySide. This change supports both the current
keyword processing as well as passing a python dict.
Thus, for example, the following becomes possible:
@ClassInfo({'RemoteObject Type': 'Simple',
'RemoteObject Signature':'c6f33edb0554ba4241aad1286a47c8189d65c845'})
class SimpleSource(QObject):
...
Task-number: PYSIDE-862
Change-Id: I7764e92a46869766582611a70628dd23d033e09c
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside/pysideclassinfo.cpp')
| -rw-r--r-- | sources/pyside6/libpyside/pysideclassinfo.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/sources/pyside6/libpyside/pysideclassinfo.cpp b/sources/pyside6/libpyside/pysideclassinfo.cpp index 6bd5a7650..01f72968d 100644 --- a/sources/pyside6/libpyside/pysideclassinfo.cpp +++ b/sources/pyside6/libpyside/pysideclassinfo.cpp @@ -136,8 +136,19 @@ static PyObject *classInfoTpNew(PyTypeObject *subtype, PyObject * /* args */, Py int classInfoTpInit(PyObject *self, PyObject *args, PyObject *kwds) { - if (PyTuple_Check(args) && PyTuple_Size(args) > 0) { - PyErr_Format(PyExc_TypeError, "ClassInfo() takes exactly 0 positional arguments (%zd given)", PyTuple_Size(args)); + PyObject *infoDict = nullptr; + auto size = PyTuple_Size(args); + if (size == 1 && !kwds) { + PyObject *tmp = PyTuple_GET_ITEM(args, 0); + if (PyDict_Check(tmp)) + infoDict = tmp; + } else if (size == 0 && kwds && PyDict_Check(kwds)) { + infoDict = kwds; + } + + if (!infoDict) { + PyErr_Format(PyExc_TypeError, "ClassInfo() takes either keyword argument(s) or " + "a single dictionary argument"); return -1; } @@ -149,12 +160,13 @@ int classInfoTpInit(PyObject *self, PyObject *args, PyObject *kwds) Py_ssize_t pos = 0; // PyDict_Next causes a segfault if kwds is empty - if (kwds && PyDict_Check(kwds) && PyDict_Size(kwds) > 0) { - while (PyDict_Next(kwds, &pos, &key, &value)) { + if (PyDict_Size(infoDict) > 0) { + while (PyDict_Next(infoDict, &pos, &key, &value)) { if (Shiboken::String::check(key) && Shiboken::String::check(value)) { pData->m_data[Shiboken::String::toCString(key)] = Shiboken::String::toCString(value); } else { - PyErr_SetString(PyExc_TypeError, "All keys and values provided to ClassInfo() must be strings"); + PyErr_SetString(PyExc_TypeError, "All keys and values provided to ClassInfo() " + "must be strings"); return -1; } } |
