2

I have a class method with an argument that ends in an underscore, from_, and I am using autoclass to generate the documentation for the class. I want the argument from_ to appear as normal text in my Sphinx documentation, but currently it appears as a hyperlink.

Here is a simplified version of the class method with the docstring:

class Twilio:

    def get_messages(to=None, from_=None):
        """
        Get messages.

        `Args:`
            to: str
                Receiver.
            from_: str
                Sender.
        `Returns:`
            Messages: dict
        """
        return fetch_messages(to=to, from_=from_)

And I am generating the documentation for this class using:

.. autoclass :: Twilio
   :inherited-members:

The problem can be seen in the get_messages function at the very bottom of this page, you can see that it is formatted as a hyperlink.

SlowLoris
  • 995
  • 6
  • 28
  • 2
    Please post your reST markup. Until then, you could make it an inline literal by enclosing it with double backticks "`". – Steve Piercy Sep 25 '20 at 17:05
  • Sorry about that, I added clarifying code, and also a link to the online documentation where you can currently see the bug in the function at the very bottom. – SlowLoris Sep 28 '20 at 17:02
  • That's still not enough information. We need the complete docstring of your method and the method itself. – Steve Piercy Sep 28 '20 at 20:35
  • Okay, my apologies, thanks for your patience. Hopefully what I just added is sufficient. – SlowLoris Sep 29 '20 at 13:23

1 Answers1

4

Use a backslash to escape the underscore.

from\_: str
     Sender.

Reference: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#escaping-mechanism

mzjn
  • 48,958
  • 13
  • 128
  • 248