Skip to content

deduperreload gives invalid tracebacks in reloaded functions #15359

Description

@yut23

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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions