MCPcopy Create free account
hub / github.com/colmap/colmap / AddDefaultsToDocstrings

Function AddDefaultsToDocstrings

src/pycolmap/helpers.h:273–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271
272template <typename T, typename... options>
273void 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
298template <typename T, typename = void>
299struct has_equality_operator : std::false_type {};

Callers 1

MakeDataclassFunction · 0.85

Calls 2

AttributeIsFunctionFunction · 0.85
StringPrintfFunction · 0.85

Tested by

no test coverage detected