Skip to content

Commit e98a2f4

Browse files
committed
Fix ipython#14230 (missing param for autoreload)
This extend the tests to actually trigger the same event as what the shell is doing, and updating the auto reload callback to accept more parameters. It also improve both the logging and test mock to log more informations on failure.
1 parent 4977b5d commit e98a2f4

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

IPython/core/events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def trigger(self, event, *args, **kwargs):
8282
func(*args, **kwargs)
8383
except (Exception, KeyboardInterrupt):
8484
if self.print_on_error:
85-
print("Error in callback {} (for {}):".format(func, event))
85+
print(
86+
"Error in callback {} (for {}), with arguments args {},kwargs {}:".format(
87+
func, event, args, kwargs
88+
)
89+
)
8690
self.shell.showtraceback()
8791

8892
# event_name -> prototype mapping

IPython/extensions/autoreload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def aimport(self, parameter_s="", stream=None):
701701
# Inject module to user namespace
702702
self.shell.push({top_name: top_module})
703703

704-
def pre_run_cell(self):
704+
def pre_run_cell(self, info):
705705
if self._reloader.enabled:
706706
try:
707707
self._reloader.check()

IPython/extensions/tests/test_autoreload.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import shutil
2222
import random
2323
import time
24+
import traceback
2425
from io import StringIO
2526
from dataclasses import dataclass
2627

@@ -31,6 +32,7 @@
3132
from IPython.extensions.autoreload import AutoreloadMagics
3233
from IPython.core.events import EventManager, pre_run_cell
3334
from IPython.testing.decorators import skipif_not_numpy
35+
from IPython.core.interactiveshell import ExecutionInfo
3436

3537
if platform.python_implementation() == "PyPy":
3638
pytest.skip(
@@ -56,8 +58,27 @@ def __init__(self):
5658

5759
register_magics = set_hook = noop
5860

61+
def showtraceback(
62+
self,
63+
exc_tuple=None,
64+
filename=None,
65+
tb_offset=None,
66+
exception_only=False,
67+
running_compiled_code=False,
68+
):
69+
traceback.print_exc()
70+
5971
def run_code(self, code):
60-
self.events.trigger("pre_run_cell")
72+
self.events.trigger(
73+
"pre_run_cell",
74+
ExecutionInfo(
75+
raw_cell="",
76+
store_history=False,
77+
silent=False,
78+
shell_futures=False,
79+
cell_id=None,
80+
),
81+
)
6182
exec(code, self.user_ns)
6283
self.auto_magics.post_execute_hook()
6384

@@ -279,6 +300,7 @@ def power(self, p):
279300
@skipif_not_numpy
280301
def test_comparing_numpy_structures(self):
281302
self.shell.magic_autoreload("2")
303+
self.shell.run_code("1+1")
282304
mod_name, mod_fn = self.new_module(
283305
textwrap.dedent(
284306
"""

0 commit comments

Comments
 (0)