[issue13223] pydoc removes 'self' in HTML for method docstrings with example code

Cameron Hayne report at bugs.python.org
Wed Oct 19 20:59:42 CEST 2011


New submission from Cameron Hayne <cameron.hayne at gmail.com>:

If the docstring for a method has example code that uses 'self',
the 'self' will not appear in the HTML generated by pydoc.writedoc

Example:
#---------------------------------
def getAnswer(self):
    """
    Return the answer.
    Example of use:
        answer = self.getAnswer()
    """
    return 42
#---------------------------------

The generated HTML will have:

getAnswer(self)
    Return the answer.
    Example of use:
        answer = getAnswer()

where the final "getAnswer" is an HTML link.
--------------------------------------------

I believe the problem arises on line 553 of the Python 2.7 version of pydoc.py which is as follows:
    results.append(self.namelink(name, methods, funcs, classes))
The appended text is the same whether or not the method call in the docstring was prefaced with 'self' or not. The 'self' has been eaten up by the regex and is in the 'selfdot' variable which is ignored by the above line.

----------
components: Library (Lib)
messages: 145937
nosy: Cameron.Hayne
priority: normal
severity: normal
status: open
title: pydoc removes 'self' in HTML for method docstrings with example code
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13223>
_______________________________________


More information about the Python-bugs-list mailing list