]> granicus.if.org Git - python/commitdiff
#14638: pydoc now treats non-str __name__ as None instead of raising
authorR David Murray <rdmurray@bitdance.com>
Mon, 23 Apr 2012 17:23:57 +0000 (13:23 -0400)
committerR David Murray <rdmurray@bitdance.com>
Mon, 23 Apr 2012 17:23:57 +0000 (13:23 -0400)
Original patch by Peter Otten.

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

index 89fd09b55670bbf805b27ce543c694d1c9bf7ae0..37616fb3edd46beb994c2f377121634a6d5175cc 100755 (executable)
@@ -1525,7 +1525,8 @@ def resolve(thing, forceload=0):
             raise ImportError('no Python documentation found for %r' % thing)
         return object, thing
     else:
-        return thing, getattr(thing, '__name__', None)
+        name = getattr(thing, '__name__', None)
+        return thing, name if isinstance(name, str) else None
 
 def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
         renderer=None):
index 65b0ab540ee286e0acc9e2ff47bf815023be9709..c5a8e983568b3b13af1ec4376e3548f8f3cba555 100644 (file)
@@ -282,6 +282,17 @@ class PydocDocTest(unittest.TestCase):
         result, doc_loc = get_pydoc_text(xml.etree)
         self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
 
+    def test_non_str_name(self):
+        # issue14638
+        # Treat illegal (non-str) name like no name
+        class A:
+            __name__ = 42
+        class B:
+            pass
+        adoc = pydoc.render_doc(A())
+        bdoc = pydoc.render_doc(B())
+        self.assertEqual(adoc.replace("A", "B"), bdoc)
+
     def test_not_here(self):
         missing_module = "test.i_am_not_here"
         result = str(run_pydoc(missing_module), 'ascii')
index fddcb7c352cabbfef7c119fecd3f6a7a8247ee4a..6feb4dac3c0f001cf1ee5533402a2e702914da05 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14638: pydoc now treats non-string __name__ values as if they
+  were missing, instead of raising an error.
+
 - Issue #13684: Fix httplib tunnel issue of infinite loops for certain sites
   which send EOF without trailing \r\n.