fix pydoc.apropos and pydoc.synopsis on modules with empty docstrings (#21548)

Patch by Yuyang Guo and Berker Peksag.
This commit is contained in:
Benjamin Peterson 2015-02-16 19:45:01 -05:00
parent 3584056ca5
commit 54237f9fea
4 changed files with 38 additions and 2 deletions

View file

@ -270,7 +270,7 @@ def synopsis(filename, cache={}):
except:
return None
del sys.modules['__temp__']
result = (module.__doc__ or '').splitlines()[0]
result = module.__doc__.splitlines()[0] if module.__doc__ else None
# Cache the result.
cache[filename] = (mtime, result)
return result
@ -2075,7 +2075,7 @@ class ModuleScanner:
if onerror:
onerror(modname)
continue
desc = (module.__doc__ or '').splitlines()[0]
desc = module.__doc__.splitlines()[0] if module.__doc__ else ''
path = getattr(module,'__file__',None)
name = modname + ' - ' + desc
if name.lower().find(key) >= 0: