Help plugin: don't fail if a topic's module is not found

Previously the help plugin failed when searching for the docstring
when a topic's module was not found. This can happen when some server
plugins are loaded (e.g. for tests).

Use empty documentation when the topic is not found.
This commit is contained in:
Petr Viktorin 2013-09-30 16:11:46 +02:00 committed by Martin Kosek
parent 15618beab6
commit dadf7cddf0

View File

@ -722,9 +722,14 @@ class help(frontend.Local):
self._topics[topic_name][2].append(c)
else:
m = '%s.%s' % (self._PLUGIN_BASE_MODULE, topic_name)
doc = (
unicode(_(sys.modules[m].__doc__)) or ''
).strip().split('\n', 1)[0]
try:
module = sys.modules[m]
except KeyError:
doc = ''
else:
doc = (
unicode(_(module.__doc__)) or ''
).strip().split('\n', 1)[0]
self._topics[topic_name] = [doc, 0, [c]]
mcl = max((self._topics[topic_name][1], len(c.name)))
self._topics[topic_name][1] = mcl