diff -r c820aa9c0c00 Lib/pydoc.py --- a/Lib/pydoc.py Fri Apr 20 18:04:03 2012 -0400 +++ b/Lib/pydoc.py Sat Apr 21 09:59:33 2012 +0200 @@ -1521,7 +1521,14 @@ raise ImportError('no Python documentation found for %r' % thing) return object, thing else: - return thing, getattr(thing, '__name__', None) + try: + name = thing.__name__ + except AttributeError: + name = None + else: + if not isinstance(name, str): + name = None + return thing, name def render_doc(thing, title='Python Library Documentation: %s', forceload=0, renderer=None): diff -r c820aa9c0c00 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Fri Apr 20 18:04:03 2012 -0400 +++ b/Lib/test/test_pydoc.py Sat Apr 21 09:59:33 2012 +0200 @@ -286,6 +286,17 @@ 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')