boostorg / python

Boost.org python module
http://boostorg.github.io/python
Boost Software License 1.0
465 stars 201 forks source link

Is it possible to programmatically retrieve C++ class name / Python class name mapping ? #424

Open Gregwar opened 9 months ago

Gregwar commented 9 months ago

Hello,

Suppose I do the following:

class_<somevendor::SomeClass>("SomePyClass");

Is there a way at runtime in Python to retrieve the mapping between SomePyClass and somevendor::SomeClass ?

For context I am writing some code to parse Doxygen XML files and producing the .pyi file to get more auto-completion and docstrings

Gregwar commented 9 months ago

Currently I am wrapping my calls to class_ with some methods like:

template <class T, class DT>
class_<T> class__(const char* name, init_base<DT> const& init)
{
  class_<T> c = class_<T>(name, init);
  register_type(typeid(T).name(), boost::python::extract<std::string>(c.attr("__name__")));
  return c;
}

(Where register_type stores the two strings in a map which is itself exposed) This works but is not really satisfying