From 126c879b406f24363bdfccffa16e62acc695aea1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 5 Apr 2009 15:05:48 +0000 Subject: [PATCH] #5453: fix SyntaxErrors using pydoc -k, caused by intentionally bad files in Pythons test suite. --- Lib/pydoc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 2aea8c0fa2..f68e72a525 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1922,8 +1922,12 @@ class ModuleScanner: if key is None: callback(None, modname, '') else: - loader = importer.find_module(modname) - if hasattr(loader,'get_source'): + try: + loader = importer.find_module(modname) + except SyntaxError: + # raised by tests for bad coding cookies or BOM + continue + if hasattr(loader, 'get_source'): try: source = loader.get_source(modname) except UnicodeDecodeError: @@ -1932,7 +1936,7 @@ class ModuleScanner: continue import io desc = source_synopsis(io.StringIO(source)) or '' - if hasattr(loader,'get_filename'): + if hasattr(loader, 'get_filename'): path = loader.get_filename(modname) else: path = None -- 2.40.0