diff options
| author | Christian Tismer <tismer@stackless.com> | 2020-09-27 14:39:25 +0200 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2020-09-29 09:27:53 +0200 |
| commit | 11179f639531c1c880498196382678b31974247d (patch) | |
| tree | d1695067feb3fea621a1ee79d615f1263a2edb7f /sources/pyside2/libpyside/feature_select.cpp | |
| parent | 50247e7d4a67e892a85dff7472f889bac97c91c7 (diff) | |
Feature-select: Implement signature-awareness of snake_case
After implementing selectable features, support from the signature
module was quite much missing. It was not clear for some time what
to do the best.
It turned out to have the smallest impact and runtime penalty
to use the Python parser output dictionaries and create copies
with snake case naming. That has almost no overhead.
Also, it was necessary to augment the internal map_dict with
snake_case versions. It may be possible to simplify that map_dict
further in another check-in.
Remaining is the problem of static properties. This will be tried
using the PySide Property objects which can be improved.
Change-Id: Ied83ccb197a3c15932c4202b5f1ade772416e17b
Task-number: PYSIDE-1019
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside2/libpyside/feature_select.cpp')
| -rw-r--r-- | sources/pyside2/libpyside/feature_select.cpp | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/sources/pyside2/libpyside/feature_select.cpp b/sources/pyside2/libpyside/feature_select.cpp index a1ba76251..b26810add 100644 --- a/sources/pyside2/libpyside/feature_select.cpp +++ b/sources/pyside2/libpyside/feature_select.cpp @@ -546,40 +546,17 @@ static bool feature_01_addLowerNames(PyTypeObject *type, PyObject *prev_dict, in // Feature 0x02: Use true properties instead of getters and setters // -static PyObject *createProperty(PyObject *getter, PyObject *setter, PyObject *doc) +static PyObject *createProperty(PyObject *getter, PyObject *setter) { assert(getter != nullptr); if (setter == nullptr) setter = Py_None; - PyObject *deleter = Py_None; PyObject *prop = PyObject_CallObject(reinterpret_cast<PyObject *>(&PyProperty_Type), nullptr); - AutoDecRef args(Py_BuildValue("OOOO", getter, setter, deleter, doc)); + AutoDecRef args(Py_BuildValue("OO", getter, setter)); PyProperty_Type.tp_init(prop, args, nullptr); return prop; } -static PyObject *calcPropDocString(PyTypeObject *type, PyObject *getterName, PyObject *setterName) -{ - // To calculate the docstring, we need the __doc__ attribute of the original - // getter and setter. We temporatily switch back to no features. This - // might change when we have full signature support for features. - auto hold = type->tp_dict; - moveToFeatureSet(type, fast_id_array[0]); - auto dict = type->tp_dict; - auto getter = PyDict_GetItem(dict, getterName); - auto setter = setterName ? PyDict_GetItem(dict, setterName) : nullptr; - PyObject *buf = PyObject_GetAttr(getter, PyMagicName::doc()); - type->tp_dict = hold; - - if (setter == nullptr) - return buf; - AutoDecRef nl(Py_BuildValue("s", "\n")); - AutoDecRef wdoc(PyObject_GetAttr(setter, PyMagicName::doc())); - String::concat(&buf, nl); - String::concat(&buf, wdoc); - return buf; -} - static QStringList parseFields(const char *propstr) { /* @@ -639,10 +616,7 @@ static bool feature_02_true_property(PyTypeObject *type, PyObject *prev_dict, in if (setter != nullptr && Py_TYPE(setter) != PepMethodDescr_TypePtr) continue; - PyObject *doc_read = make_snake_case(fields[1], false); - PyObject *doc_write(haveWrite ? make_snake_case(fields[2], false) : nullptr); - AutoDecRef doc(calcPropDocString(type, doc_read, doc_write)); - AutoDecRef PyProperty(createProperty(getter, setter, doc)); + AutoDecRef PyProperty(createProperty(getter, setter)); if (PyProperty.isNull()) return false; if (PyDict_SetItem(prop_dict, name, PyProperty) < 0) |
