aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysideproperty.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-11-03 09:53:13 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-11-03 14:10:00 +0100
commit2aff6a35a9aa2f233c9801456daa6986437d2647 (patch)
treea677819e66ba4fd6cf59f408eb8f313bb2659c1a /sources/pyside6/libpyside/pysideproperty.cpp
parentc1fbb035daf8940fd134bb9065da1154af225bd0 (diff)
PySide6/Property: Fix read-only properties when using the decorator syntax
The @setter decorator causes the property to be recreated with Py_None set for the non-existent members, apparently due to a long-closed Python bug (see_property_copy()). As a band-aid fix, check for Py_None. Fixes: PYSIDE-3227 Pick-to: 6.10 Change-Id: Ib818e9930bd598306270377e26e625bfa9692a92 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/pysideproperty.cpp')
-rw-r--r--sources/pyside6/libpyside/pysideproperty.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp
index 1cea7d53d..c72bc381a 100644
--- a/sources/pyside6/libpyside/pysideproperty.cpp
+++ b/sources/pyside6/libpyside/pysideproperty.cpp
@@ -46,6 +46,7 @@ static PyObject *qProperty_fdel(PyObject *, void *);
static PyMethodDef PySidePropertyMethods[] = {
{"getter", reinterpret_cast<PyCFunction>(qPropertyGetter), METH_O, nullptr},
+ // "name@setter" handling
{"setter", reinterpret_cast<PyCFunction>(qPropertySetter), METH_O, nullptr},
{"resetter", reinterpret_cast<PyCFunction>(qPropertyResetter), METH_O, nullptr},
{"deleter", reinterpret_cast<PyCFunction>(qPropertyDeleter), METH_O, nullptr},
@@ -114,7 +115,7 @@ PyObject *PySidePropertyPrivate::getValue(PyObject *source) const
int PySidePropertyPrivate::setValue(PyObject *source, PyObject *value)
{
- if (fset && value) {
+ if (fset != nullptr && fset != Py_None && value != nullptr) {
Shiboken::AutoDecRef args(PyTuple_New(2));
PyTuple_SetItem(args, 0, source);
PyTuple_SetItem(args, 1, value);
@@ -123,7 +124,7 @@ int PySidePropertyPrivate::setValue(PyObject *source, PyObject *value)
Shiboken::AutoDecRef result(PyObject_CallObject(fset, args));
return (result.isNull() ? -1 : 0);
}
- if (fdel) {
+ if (fdel != nullptr && fdel != Py_None) {
Shiboken::AutoDecRef args(PyTuple_New(1));
PyTuple_SetItem(args, 0, source);
Py_INCREF(source);
@@ -136,7 +137,7 @@ int PySidePropertyPrivate::setValue(PyObject *source, PyObject *value)
int PySidePropertyPrivate::reset(PyObject *source)
{
- if (freset) {
+ if (freset != nullptr && freset != Py_None) {
Shiboken::AutoDecRef args(PyTuple_New(1));
Py_INCREF(source);
PyTuple_SetItem(args, 0, source);
@@ -559,12 +560,12 @@ bool isReadable(const PySideProperty * /* self */)
bool isWritable(const PySideProperty *self)
{
- return self->d->fset != nullptr;
+ return self->d->fset != nullptr && self->d->fset != Py_None;
}
bool hasReset(const PySideProperty *self)
{
- return self->d->freset != nullptr;
+ return self->d->freset != nullptr && self->d->freset != Py_None;
}
bool isDesignable(const PySideProperty *self)