| 271 | |
| 272 | template <typename T, typename... options> |
| 273 | void AddDefaultsToDocstrings(py::classh<T, options...> cls) { |
| 274 | auto obj = cls(); |
| 275 | for (auto& handle : obj.attr("__dir__")()) { |
| 276 | const std::string attribute = py::str(handle); |
| 277 | py::object member; |
| 278 | try { |
| 279 | member = obj.attr(attribute.c_str()); |
| 280 | } catch (const std::exception&) { |
| 281 | // Some properties are not valid for some uninitialized objects. |
| 282 | continue; |
| 283 | } |
| 284 | auto prop = cls.attr(attribute.c_str()); |
| 285 | if (AttributeIsFunction(attribute, member)) { |
| 286 | continue; |
| 287 | } |
| 288 | const auto type_name = py::type::of(member).attr("__name__"); |
| 289 | const std::string doc = |
| 290 | colmap::StringPrintf("%s (%s, default: %s)", |
| 291 | py::str(prop.doc()).cast<std::string>().c_str(), |
| 292 | type_name.template cast<std::string>().c_str(), |
| 293 | py::str(member).cast<std::string>().c_str()); |
| 294 | prop.doc() = py::str(doc); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | template <typename T, typename = void> |
| 299 | struct has_equality_operator : std::false_type {}; |
no test coverage detected