The solution that works for Sphinx is to prefix the reference with ~.
Per the Sphinx documentation on Cross-referencing Syntax,
If you prefix the content with
~, the link text will only be the last component of the target. For example,:py:meth:`~Queue.Queue.get`will refer toQueue.Queue.getbut only displaygetas the link text.
So the answer is:
class MyClass():
def foo(self):
print 'foo'
def bar(self):
"""This method does the same as :func:`~mymodule.MyClass.foo`"""
print 'foo'
This results in an HTML looking like this : This method does the same as foo(), and foo() is a link.
However, note that this may not display in Spyder as a link.
If you want to manually specify the text of the link you can use:
:func:`my text <mymodule.MyClass.foo>`
For more information, checkout Cross-referencing Python objects.
If you're using sphinx to generate your documentation
"""
`here <url>`__
"""
in your docstrings should be parsed properly.
Just add the link as a string into the docstring, like so:
def foo():
"""Lorem ipsum for more info, see here: www.myfancydocu.com""
The doctring is just a string, so there is no Hyperlink. But anyone that wants to look at the website can just copy the link.
There are automatic documentation-builders that build a documentation out of your code and docstrings in e.g. html. Those can probably add hyperlinks to the documentation with a specific syntax, but that syntax then depends on which documentation-builder you use. If you only have your code, then just adding the url as a string is all you can do.