-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
pydoc removes 'self' in HTML for method docstrings with example code #57432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If the docstring for a method has example code that uses 'self', 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: |
FWIU, only the name of the method, getAnswer, would be a HTML link in the "self.getAnswer()" line that pydoc should generate, while strong (highlighted) text would be used for instance attributes. I have written a patch for that, by checking for "self." matches (and differentiating between methods and instance attributes) *before* trying to match functions or class instantiations. It seems to work, but I will test it thoroughly tomorrow. |
Patch updated with the test cases. I have added a third class to Lib/test/pydoc_mod.py and updated two of the existing cases, test_text_doc and test_html_doc, accordingly. The news entry could be: "Issue bpo-13223: Fix pydoc.writedoc so that the HTML documentation for methods that use 'self' in the example code is generated correctly." |
Patch looks good to me. Ezio, do you have time to review too? (I had forgotten that there were tests checking the exact HTML output. This won’t be fun when we overhaul pydoc to make it generate sensible HTML.) |
Víctor, can you address my comment on rietveld? |
The patch still applies cleanly, so I've just updated the comment. test passes, make patchcheck passes. |
New changeset 7aa72075d440 by Benjamin Peterson in branch '3.4': New changeset e89c39125892 by Benjamin Peterson in branch '2.7': New changeset cddb17c4975e by Benjamin Peterson in branch 'default': |
I guess the tests --without-doc-strings are broken: |
Attached patch fixes these failures. |
Berker, I've committed your patch, thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: