FeaturePython objects include the Python class's __repr__ it their __repr__ (#24462)

This commit is contained in:
Steven James
2026-02-16 10:57:14 -06:00
committed by GitHub
parent 72a024aaeb
commit 8567dce28a
2 changed files with 35 additions and 1 deletions
+19 -1
View File
@@ -33,7 +33,25 @@ using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string AttachExtensionPy::representation() const
{
return {"<Part::AttachableObject>"};
auto* P = getAttachExtensionPtr()->getExtendedObject()->getPropertyByName("Proxy");
if (P) {
PyObject* Featclass = static_cast<App::PropertyPythonObject*>(P)->getValue().ptr();
PyObject* repstr = PyObject_Repr(Featclass);
if (repstr) {
Py_ssize_t len;
std::string ret = fmt::format(
"<Attachable {} ({})>\n",
getAttachExtensionPtr()->getExtendedObject()->getTypeId().getName(),
PyUnicode_AsUTF8AndSize(repstr, &len)
);
Py_DECREF(repstr);
return ret;
}
}
return fmt::format(
"<Attachable {}>",
getAttachExtensionPtr()->getExtendedObject()->getTypeId().getName()
);
}
PyObject* AttachExtensionPy::positionBySupport(PyObject* args)
+16
View File
@@ -37,6 +37,22 @@ using namespace Part;
// returns a string which represent the object e.g. when printed in python
std::string PartFeaturePy::representation() const
{
auto* P = getFeaturePtr()->getPropertyByName("Proxy");
if (P) {
PyObject* Featclass = static_cast<App::PropertyPythonObject*>(P)->getValue().ptr();
PyObject* repstr = PyObject_Repr(Featclass);
if (repstr) {
Py_ssize_t len;
std::string ret = fmt::format(
"<{} ({})>\n",
static_cast<std::string>(getTypeId()),
PyUnicode_AsUTF8AndSize(repstr, &len)
);
Py_DECREF(repstr);
return ret;
}
}
return fmt::format("<{}>", static_cast<std::string>(getTypeId()));
}