mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
#14638: pydoc now treats non-str __name__ as None instead of raising
Original patch by Peter Otten.
This commit is contained in:
parent
4c20c4e198
commit
c313b1d9b0
3 changed files with 16 additions and 1 deletions
|
@ -1498,7 +1498,8 @@ def resolve(thing, forceload=0):
|
||||||
raise ImportError, 'no Python documentation found for %r' % thing
|
raise ImportError, 'no Python documentation found for %r' % thing
|
||||||
return object, thing
|
return object, thing
|
||||||
else:
|
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):
|
def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
|
||||||
"""Render text documentation, given an object or a path to an object."""
|
"""Render text documentation, given an object or a path to an object."""
|
||||||
|
|
|
@ -249,6 +249,17 @@ class PyDocDocTest(unittest.TestCase):
|
||||||
result, doc_loc = get_pydoc_text(xml.etree)
|
result, doc_loc = get_pydoc_text(xml.etree)
|
||||||
self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
|
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):
|
def test_not_here(self):
|
||||||
missing_module = "test.i_am_not_here"
|
missing_module = "test.i_am_not_here"
|
||||||
result = run_pydoc(missing_module)
|
result = run_pydoc(missing_module)
|
||||||
|
|
|
@ -50,6 +50,9 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #13684: Fix httplib tunnel issue of infinite loops for certain sites
|
||||||
which send EOF without trailing \r\n.
|
which send EOF without trailing \r\n.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue