App: still support __getstate__/__setstate__ for add-ons for < Py3.11

This commit is contained in:
wmayer
2023-09-25 13:31:14 +02:00
committed by wwmayer
parent c1d1a4fd1f
commit 58adf212d9

View File

@@ -92,6 +92,14 @@ std::string PropertyPythonObject::toString() const
Py::Callable state(this->object.getAttr("dumps"));
dump = state.apply(args);
}
#if PY_VERSION_HEX < 0x030b0000
// support add-ons that use the old method names
else if (this->object.hasAttr("__getstate__")) {
Py::Tuple args;
Py::Callable state(this->object.getAttr("__getstate__"));
dump = state.apply(args);
}
#endif
else if (this->object.hasAttr("__dict__")) {
dump = this->object.getAttr("__dict__");
}
@@ -135,6 +143,15 @@ void PropertyPythonObject::fromString(const std::string& repr)
Py::Callable state(this->object.getAttr("loads"));
state.apply(args);
}
#if PY_VERSION_HEX < 0x030b0000
// support add-ons that use the old method names
else if (this->object.hasAttr("__setstate__")) {
Py::Tuple args(1);
args.setItem(0, res);
Py::Callable state(this->object.getAttr("__setstate__"));
state.apply(args);
}
#endif
else if (this->object.hasAttr("__dict__")) {
if (!res.isNone()) {
this->object.setAttr("__dict__", res);