Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Displaying function call as mylib.hello() instead of hello() #739

Closed
rudymatela opened this issue Sep 5, 2024 · 1 comment
Closed

Displaying function call as mylib.hello() instead of hello() #739

rudymatela opened this issue Sep 5, 2024 · 1 comment

Comments

@rudymatela
Copy link

Consider the following short library mylib.py:

"""
This is the documentation for mylib.
You can use it like so:

    import mylib
    mylib.hello()
"""

def hello():
    """
    A function that says hello:

    >>> import mylib
    >>> mylib.hello()
    Hello
    """
    print("Hello")

We can compile docs with the following:

$ pdoc mylib.py -o docs

This is the result I get:

mylib

The code in the documentation is like this:

import mylib
hello()

The second line of code myilb.hello() is being displayed as just hello(). I would like to get the following instead:

import mylib
mylib.hello()

Is there a way do configure pdoc to generate the documentation like this? I tried looking in the command line flags and online but I could not find a way. 😔

Reasoning

If one copy-pastes the code from the docs import mylib; hello(), one would get a parse/compile/runtime error. It would be nice if pdoc could keep the same notation used in the docstring comment: with or without the library name before.

For some libraries, the usual way of calling them is with the explicit "namespaces" in calls, e.g.:

unittest.main()
# or
doctest.testmod()

It would be nice to be able to display this using pdoc as well.

Versions

$ pdoc --version
pdoc: 14.5.1
Python: 3.12.4
Platform: Linux-6.10.4-arch2-1-x86_64-with-glibc2.40
@rudymatela
Copy link
Author

@mhils, thanks a lot for fixing this issue so speedily. Wow! ... and with a new version release no less:

$ pdoc --version
pdoc: 14.7.0
Python: 3.12.4
Platform: Linux-6.10.4-arch2-1-x86_64-with-glibc2.40

$ pdoc mylib.py -o docs

mylib

You rock! 🤘 😄 🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant