2

I am looking to autodoc some functions in a Python module using autofunction. Let's say, for example, the functions are defined in mylib/funcs/a.py and that file looks something like this:

def myfunc(arg):
    """ My function does something """
    return

My intent is to have users call that function from the root of the library rather than at that file/module path. In other words mylib.myfunc rather than mylib.funcs.a.myfunc.

However, for reasons outside of the scope of this question that I'd rather not get in to, when you do import mylib; mylib.myfunc or do from mylib import myfunc it doesn't point to the actual function where the docstring is.

I can get the function to auto doc like so:

..currentmodule:: mylib.funcs.a
..autofunction:: myfunc

However, the resulting documentation has a signature that looks like mylib.funcs.a.myfunc. I would like it to just be mylib.myfunc.

If I wasn't using autodoc I could do something like this in my sphinx docs:

.. function:: myfunc(arg)
    :module: mylib

So I suppose my question is this: Is there a way to "alias" or change the label of a module when using autodoc on a function? I have looked at the preprocessing events for processing a docstring and the signature but those don't seem to allow you to change how the module is displayed.

Matt Dodge
  • 10,833
  • 7
  • 38
  • 58
  • Do you have a `mylib/__init__.py` file where you import the function? Perhaps these questions will help: https://stackoverflow.com/q/15115514/407651, https://stackoverflow.com/q/22096187/407651 – mzjn May 15 '19 at 03:55
  • @mzjn Unfortunately I don't. Or rather the function that is linked in the `__init__.py` points to a different function def/docstring. It's a somewhat bizarre setup but I don't think the `__init__.py` method will work. I did try setting `__module__` in various places, hoping that would work but couldn't make that happen either. – Matt Dodge May 15 '19 at 15:19
  • I think you need to provide a [mcve] that explains your "bizarre" setup. – mzjn May 17 '19 at 07:22

0 Answers0