1515
1616from __future__ import annotations
1717
18- from typing import TYPE_CHECKING , Any , Callable , Iterable
18+ from typing import TYPE_CHECKING , Any , Callable , Iterable , TypeVar
1919
2020if TYPE_CHECKING :
21- from IPython .core .interactiveshell import InteractiveShell
21+ from IPython .core .interactiveshell import (
22+ ExecutionInfo ,
23+ ExecutionResult ,
24+ InteractiveShell ,
25+ )
2226
2327
2428class EventManager :
@@ -106,7 +110,10 @@ def trigger(self, event: str, *args: Any, **kwargs: Any) -> None:
106110# event_name -> prototype mapping
107111available_events : dict [str , Callable [..., Any ]] = {}
108112
109- def _define_event (callback_function : Callable [..., Any ]) -> Callable [..., Any ]:
113+ _CallbackT = TypeVar ("_CallbackT" , bound = Callable [..., Any ])
114+
115+ def _define_event (callback_function : _CallbackT ) -> _CallbackT :
116+ """Decorator to register a function as an available event prototype."""
110117 available_events [callback_function .__name__ ] = callback_function
111118 return callback_function
112119
@@ -127,7 +134,7 @@ def pre_execute() -> None:
127134 pass
128135
129136@_define_event
130- def pre_run_cell (info : Any ) -> None :
137+ def pre_run_cell (info : ExecutionInfo ) -> None :
131138 """Fires before user-entered code runs.
132139
133140 Parameters
@@ -147,7 +154,7 @@ def post_execute() -> None:
147154 pass
148155
149156@_define_event
150- def post_run_cell (result : Any ) -> None :
157+ def post_run_cell (result : ExecutionResult ) -> None :
151158 """Fires after user-entered code runs.
152159
153160 Parameters
0 commit comments