gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

Importing ipdb initializes IPython #223

Closed adamchainz closed 3 years ago

adamchainz commented 3 years ago

Currently, merely importing ipdb causes it to initialize IPython. In turn, among other things, IPython installs its excepthook. Therefore on programs that import ipdb, the default exception behaviour is already wrapped with IPython's, even when both ipdb and IPython aren't run.

For example, take this program:

$ cat test.py
import ipdb

1 / 0

Running it with the latest master of ipdb, and most released versions, gives this error message:

$ python test.py
Traceback (most recent call last):
  File "/.../ipdb/test.py", line 3, in <module>
    1 / 0
ZeroDivisionError: division by zero

If you suspect this is an IPython 7.21.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

The IPython banner doesn't make any sense since, whilst instantiated, IPython was not used. I'd expect only Python's default exception output:

python test.py
Traceback (most recent call last):
  File "/.../ipdb/test.py", line 3, in <module>
    1 / 0
ZeroDivisionError: division by zero

This probably affects a lot of users through at least Django's test runner, which imports ipdb if available.