summaryrefslogtreecommitdiff
path: root/sphinx/events.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-06-04 00:18:30 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-06-04 00:18:30 +0900
commit068b9b5738b4d41a25e14d56d6f6b55f3bc8d443 (patch)
treef58f2d43d8a54545ae8a0c51ffe99c310864710d /sphinx/events.py
parent88a3548a8268d3b99f2d79db08fe65da7d691592 (diff)
parent9b45b00bd4cee7dad96b98cec0224f88a84ef40a (diff)
downloadsphinx-git-068b9b5738b4d41a25e14d56d6f6b55f3bc8d443.tar.gz
Merge branch '3.x'
Diffstat (limited to 'sphinx/events.py')
-rw-r--r--sphinx/events.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/sphinx/events.py b/sphinx/events.py
index fae870b4b..3a3753895 100644
--- a/sphinx/events.py
+++ b/sphinx/events.py
@@ -12,7 +12,7 @@
from collections import defaultdict
from operator import attrgetter
-from typing import Any, Callable, Dict, List, NamedTuple
+from typing import Any, Callable, Dict, List, NamedTuple, Tuple, Type
from typing import TYPE_CHECKING
from sphinx.errors import ExtensionError, SphinxError
@@ -83,7 +83,8 @@ class EventManager:
if listener.id == listener_id:
listeners.remove(listener)
- def emit(self, name: str, *args: Any) -> List:
+ def emit(self, name: str, *args: Any,
+ allowed_exceptions: Tuple[Type[Exception], ...] = ()) -> List:
"""Emit a Sphinx event."""
try:
logger.debug('[app] emitting event: %r%s', name, repr(args)[:100])
@@ -97,6 +98,9 @@ class EventManager:
for listener in listeners:
try:
results.append(listener.handler(self.app, *args))
+ except allowed_exceptions:
+ # pass through the errors specified as *allowed_exceptions*
+ raise
except SphinxError:
raise
except Exception as exc:
@@ -104,12 +108,13 @@ class EventManager:
(listener.handler, name)) from exc
return results
- def emit_firstresult(self, name: str, *args: Any) -> Any:
+ def emit_firstresult(self, name: str, *args: Any,
+ allowed_exceptions: Tuple[Type[Exception], ...] = ()) -> Any:
"""Emit a Sphinx event and returns first result.
This returns the result of the first handler that doesn't return ``None``.
"""
- for result in self.emit(name, *args):
+ for result in self.emit(name, *args, allowed_exceptions=allowed_exceptions):
if result is not None:
return result
return None