]> granicus.if.org Git - python/commitdiff
don't remove self from example code in the HTML output (closes #13223)
authorBenjamin Peterson <benjamin@python.org>
Sat, 7 Jun 2014 23:44:00 +0000 (16:44 -0700)
committerBenjamin Peterson <benjamin@python.org>
Sat, 7 Jun 2014 23:44:00 +0000 (16:44 -0700)
Patch by Víctor Terrón.

Lib/pydoc.py
Lib/test/pydoc_mod.py
Lib/test/test_pydoc.py
Misc/NEWS

index 220a3cb1ccc8071a3933c73b6e4048267dd8ae9d..2dee6eee23d40f1835c7427a1edc435107daf234 100755 (executable)
@@ -595,10 +595,15 @@ class HTMLDoc(Doc):
             elif pep:
                 url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
                 results.append('<a href="%s">%s</a>' % (url, escape(all)))
+            elif selfdot:
+                # Create a link for methods like 'self.method(...)'
+                # and use <strong> for attributes like 'self.attr'
+                if text[end:end+1] == '(':
+                    results.append('self.' + self.namelink(name, methods))
+                else:
+                    results.append('self.<strong>%s</strong>' % name)
             elif text[end:end+1] == '(':
                 results.append(self.namelink(name, methods, funcs, classes))
-            elif selfdot:
-                results.append('self.<strong>%s</strong>' % name)
             else:
                 results.append(self.namelink(name, classes))
             here = end
index f86b5c621e3472da10a8632b61508899b32b593d..cda1c9e23131b5dda3d685a7c4a847afe3faac7f 100644 (file)
@@ -15,6 +15,16 @@ class B(object):
     NO_MEANING = "eggs"
     pass
 
+class C(object):
+    def say_no(self):
+        return "no"
+    def get_answer(self):
+        """ Return say_no() """
+        return self.say_no()
+    def is_it_true(self):
+        """ Return self.get_answer() """
+        return self.get_answer()
+
 def doc_func():
     """
     This function solves all of the world's problems:
index f26fb15f535cbb857cedd8cfaa4c33eed31d397c..188c4c26feb8f0d30d2a6915eedf3bd7c6c75880 100644 (file)
@@ -47,6 +47,7 @@ CLASSES
     builtins.object
         A
         B
+        C
 \x20\x20\x20\x20
     class A(builtins.object)
      |  Hello and goodbye
@@ -74,6 +75,26 @@ CLASSES
      |  Data and other attributes defined here:
      |\x20\x20
      |  NO_MEANING = 'eggs'
+\x20\x20\x20\x20
+    class C(builtins.object)
+     |  Methods defined here:
+     |\x20\x20
+     |  get_answer(self)
+     |      Return say_no()
+     |\x20\x20
+     |  is_it_true(self)
+     |      Return self.get_answer()
+     |\x20\x20
+     |  say_no(self)
+     |\x20\x20
+     |  ----------------------------------------------------------------------
+     |  Data descriptors defined here:
+     |\x20\x20
+     |  __dict__
+     |      dictionary for instance variables (if defined)
+     |\x20\x20
+     |  __weakref__
+     |      list of weak references to the object (if defined)
 
 FUNCTIONS
     doc_func()
@@ -124,6 +145,7 @@ expected_html_pattern = """
 <dl>
 <dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#A">A</a>
 </font></dt><dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#B">B</a>
+</font></dt><dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#C">C</a>
 </font></dt></dl>
 </dd>
 </dl>
@@ -165,6 +187,28 @@ Data descriptors defined here:<br>
 Data and other attributes defined here:<br>
 <dl><dt><strong>NO_MEANING</strong> = 'eggs'</dl>
 
+</td></tr></table> <p>
+<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
+<tr bgcolor="#ffc8d8">
+<td colspan=3 valign=bottom>&nbsp;<br>
+<font color="#000000" face="helvetica, arial"><a name="C">class <strong>C</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
+\x20\x20\x20\x20
+<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
+<td width="100%%">Methods defined here:<br>
+<dl><dt><a name="C-get_answer"><strong>get_answer</strong></a>(self)</dt><dd><tt>Return&nbsp;<a href="#C-say_no">say_no</a>()</tt></dd></dl>
+
+<dl><dt><a name="C-is_it_true"><strong>is_it_true</strong></a>(self)</dt><dd><tt>Return&nbsp;self.<a href="#C-get_answer">get_answer</a>()</tt></dd></dl>
+
+<dl><dt><a name="C-say_no"><strong>say_no</strong></a>(self)</dt></dl>
+
+<hr>
+Data descriptors defined here:<br>
+<dl><dt><strong>__dict__</strong></dt>
+<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
+<dl><dt><strong>__weakref__</strong></dt>
+<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
+</dl>
 </td></tr></table></td></tr></table><p>
 <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
 <tr bgcolor="#eeaa77">
index f581cd458021cc8a5c56ed072918393a118029b0..57090b65624f0df20ae69b95daf65c0bed6ab790 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #13223: Fix pydoc.writedoc so that the HTML documentation for methods
+  that use 'self' in the example code is generated correctly.
+
 - Issue #21463: In urllib.request, fix pruning of the FTP cache.
 
 - Issue #21618: The subprocess module could fail to close open fds that were