You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using pybind11 to create private extension modules which are then accompanied by a pure python wrapper with a public name.
Example:
my_ext_mod/
├── __init__.py
├── _my_ext_mod.pyd
In the init.py, I basically reexport the extension module such that all bound c++ objects have __module__ equal to my_ext_mod. This makes the extension module 'transparent' and the user never sees any private _my_ext_mod. Tools like pybnd11-stubgen and Sphinx work perfectly with this, except for one thing, the docstring in pybind11 add the full qualifier so a class in Sphinx is documented as:
class Dummy
def my_func(self: _my_ext_mod.Dummy)
which is undesirable. It would be great if pybind11 could offer a way to handle this, I'm quite sure the private extension module approach is quite common. Perhaps something like:
PYBIND11_MODULE(_my_ext_mod, mod, my_ext_mod)
which adds an additional attribute like __public_module__ to all exposed attributes which is then used in the docstring generation?
But perhaps there are better and even already existing solutions?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using pybind11 to create private extension modules which are then accompanied by a pure python wrapper with a public name.
Example:
In the init.py, I basically reexport the extension module such that all bound c++ objects have
__module__equal tomy_ext_mod. This makes the extension module 'transparent' and the user never sees any private_my_ext_mod. Tools like pybnd11-stubgen and Sphinx work perfectly with this, except for one thing, the docstring in pybind11 add the full qualifier so a class in Sphinx is documented as:class Dummy def my_func(self: _my_ext_mod.Dummy)which is undesirable. It would be great if pybind11 could offer a way to handle this, I'm quite sure the private extension module approach is quite common. Perhaps something like:
PYBIND11_MODULE(_my_ext_mod, mod, my_ext_mod)which adds an additional attribute like
__public_module__to all exposed attributes which is then used in the docstring generation?But perhaps there are better and even already existing solutions?
Beta Was this translation helpful? Give feedback.
All reactions