ipython / ipython/ipython

deduperreload gives invalid tracebacks in reloaded functions

Open
#15,359 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

When a function is reloaded with deduperreload, the line number information from the source file is lost. This breaks tracebacks, causing them to point to the start of the file instead of the correct source line. The reported line number matches the offset from the start of the function (plus one if the function is inside a class), but any comments and blank lines are ignored.

Tested with Python 3.13.14, IPython 9.15.0.

```python
Python 3.13.14 | packaged by conda-forge | (main, Jun 12 2026, 09:50:25) [GCC 14.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %load_ext autoreload

In [2]: %autoreload -p 1

In [3]: %%writefile module.py
...: """
...: The traceback incorrectly points to this line (line 2 of the file)
...: """
...: def func():
...: assert False, "before reload"
...:
...:

In [4]: %aimport module

In [5]: module.func()
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[5], line 1
----> 1 module.func()

File /tmp/module.py:5, in func()
4 def func():
----> 5 assert False, "before reload"

AssertionError: before reload

In [6]: %%writefile module.py
...: """
...: The traceback incorrectly points to this line (line 2 of the file)
...: """
...: def func():
...: assert False, "after reload"
...:
...:
Overwriting module.py

In [7]: module.func()
Reloading 'module'.
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[7], line 1
----> 1 module.func()

File /tmp/module.py:2, in func()
1 """
----> 2 The traceback incorrectly points to this line (line 2 of the file)
3 """
4 def func():
5 assert False, "after reload"

AssertionError: after reload
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the problem with the provided module.py example, using IPython's %autoreload entry point and the deduperreload path. Trace how the reloaded function is created and verify that a traceback after reload points to the actual assertion line, including when comments, blank lines, or a class surround the function.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.