Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython (3.2): #14638: pydoc now treats non-str name as None instead of raising

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Apr 23, 2012, 10:27 AM

Post #1 of 1 (44 views)
Permalink
cpython (3.2): #14638: pydoc now treats non-str name as None instead of raising

http://hg.python.org/cpython/rev/2a35dfbe3d99
changeset: 76497:2a35dfbe3d99
branch: 3.2
parent: 76493:26631c56d81f
user: R David Murray <rdmurray [at] bitdance>
date: Mon Apr 23 13:23:57 2012 -0400
summary:
#14638: pydoc now treats non-str __name__ as None instead of raising

Original patch by Peter Otten.

files:
Lib/pydoc.py | 3 ++-
Lib/test/test_pydoc.py | 11 +++++++++++
Misc/NEWS | 3 +++
3 files changed, 16 insertions(+), 1 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1525,7 +1525,8 @@
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):
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -282,6 +282,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')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,9 @@
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.


--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.