Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 126c879

Browse files
committed
#5453: fix SyntaxErrors using pydoc -k, caused by intentionally bad files in Pythons test suite.
1 parent 236f797 commit 126c879

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/pydoc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,8 +1922,12 @@ def run(self, callback, key=None, completer=None, onerror=None):
19221922
if key is None:
19231923
callback(None, modname, '')
19241924
else:
1925-
loader = importer.find_module(modname)
1926-
if hasattr(loader,'get_source'):
1925+
try:
1926+
loader = importer.find_module(modname)
1927+
except SyntaxError:
1928+
# raised by tests for bad coding cookies or BOM
1929+
continue
1930+
if hasattr(loader, 'get_source'):
19271931
try:
19281932
source = loader.get_source(modname)
19291933
except UnicodeDecodeError:
@@ -1932,7 +1936,7 @@ def run(self, callback, key=None, completer=None, onerror=None):
19321936
continue
19331937
import io
19341938
desc = source_synopsis(io.StringIO(source)) or ''
1935-
if hasattr(loader,'get_filename'):
1939+
if hasattr(loader, 'get_filename'):
19361940
path = loader.get_filename(modname)
19371941
else:
19381942
path = None

0 commit comments

Comments
 (0)