Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPDB loads readline despite claiming not to #13791

Open
jdtsmith opened this issue Oct 17, 2022 · 2 comments
Open

iPDB loads readline despite claiming not to #13791

jdtsmith opened this issue Oct 17, 2022 · 2 comments

Comments

@jdtsmith
Copy link
Contributor

jdtsmith commented Oct 17, 2022

Despite its code indicating that iPDB doesn't load readline:

% ipython 
Python 3.10.6 (main, Aug 30 2022, 05:12:36) [Clang 13.1.6 (clang-1316.0.21.2.5)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In [1], line 1
----> 1 1/0

ZeroDivisionError: division by zero

In [2]: import sys

In [3]: sys.modules.get('readline') # Nothing!

In [4]: %debug
> <ipython-input-1-9e1622b385b6>(1)<module>()
----> 1 1/0

ipdb>   # Ctrl-d to exit                                                                        


In [5]: sys.modules.get('readline')
Out[5]: <module 'readline' from '/usr/local/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/readline.cpython-310-darwin.so'>

In [6]: 

Can also be seen by running under python -v -m IPython:

In [1]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In [1], line 1
----> 1 1/0

ZeroDivisionError: division by zero

In [2]: %debug
# extension module 'readline' loaded from '/usr/local/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/readline.cpython-310-darwin.so'
# extension module 'readline' executed from '/usr/local/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload/readline.cpython-310-darwin.so'
import 'readline' # <_frozen_importlib_external.ExtensionFileLoader object at 0x10d14b070>
> <ipython-input-1-9e1622b385b6>(1)<module>()
----> 1 1/0

ipdb> 

This leads to issues accepting raw control characters (see #13775).

@jdtsmith
Copy link
Contributor Author

I tracked this down: Pdb itself (which iPDB inherits from) loads readline unconditionally. So nothing IPython can do about it (aside maybe from patching builtins.__import__).

@jdtsmith jdtsmith reopened this Nov 14, 2022
@jdtsmith
Copy link
Contributor Author

jdtsmith commented Nov 14, 2022

OK, the real issue is that the new iPython Pdb (confusingly also called "Pdb"), initializes OldPdb:

        OldPdb.__init__(self, completekey, stdin, stdout, **kwargs)

which, due to the above referenced Pdb itself code, imports readline. So the docstring statement for new Pdb of:

"""Modified Pdb class, does not load readline."""

is incorrect. It does not directly load readline, but it causes it to be loaded via the parent class. This is only valid when TerminalPdb is not used, i.e. with simpleprompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant