diff options
author | Christian Tismer <tismer@stackless.com> | 2020-08-28 15:22:14 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2020-08-31 11:24:27 +0200 |
commit | 9a37b64bbee7573578f63334b76a3eca533ea539 (patch) | |
tree | 92dc83e5c0188d68cea207b029978f8f5e5abb8b /sources/shiboken2/libshiboken/basewrapper.cpp | |
parent | d92a25a384f4828c3d59d06d81a456f675cbaa26 (diff) |
shiboken: Fix __doc__ setter for derived types
This setter makes sure that __doc__ for derived SbkObject types
behaves like a data descriptor.
Change-Id: I4ca1d4a224755304d9a9223b9fd6244af94d981f
Fixes: PYSIDE-1177
Task-number: PYSIDE-908
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken/basewrapper.cpp')
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index 1960e5932..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 }; |