Skip to content

Commit

Permalink
App: fix PropertyPythonObject persistence backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Feb 3, 2024
1 parent af9c60f commit 9a7e85e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/App/PropertyPythonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,17 @@ 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__")) {
else if (this->object.hasAttr("__getstate__")
#if PY_VERSION_HEX >= 0x030b0000
&& this->object.getAttr("__getstate__").hasAttr("__func__")
#endif
)
{
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__");
}
Expand Down Expand Up @@ -143,15 +146,18 @@ 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__")) {
else if (this->object.hasAttr("__setstate__")
#if PY_VERSION_HEX >= 0x030b0000
&& this->object.getAttr("__setstate__").hasAttr("__func__")
#endif
)
{
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);
Expand Down

0 comments on commit 9a7e85e

Please sign in to comment.