[Python-bugs-list] [ python-Bugs-676342 ] after using pdb readline does not work correctly

SourceForge.net noreply@sourceforge.net
Wed, 29 Jan 2003 10:19:28 -0800


Bugs item #676342, was opened at 2003-01-28 20:53
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=676342&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Stone (mbrierst)
Assigned to: Nobody/Anonymous (nobody)
Summary: after using pdb readline does not work correctly

Initial Comment:

After I use pdb in the interpreter my readline settings are messed up.  It only knows about the pdb readline stuff forever afterward.  In fact, this happens as soon as a Pdb object is instantiated, regardless of whether or not you use it.

This is a result of some aspects of the Cmd object in Lib/cmd.py.

Currently Cmd registers a new readline completer as soon as a Cmd object is instantiated.  This is probably incorrect.  I believe the correct place to register the new handler is in the preloop hook.  That way the new readline completer is only used while the Cmd object is actually responsible for processing user input.

Next, the old readline completer should probably be re-registered in the postloop hook.  In order to do this, a new call must be added to the readline module to return the current completer so it can be saved and later restored.

The files included patch readline.c (version 2.41.64) and cmd.py (version 1.26.16.2) to make the changes described above.  After this patch readline works as expected in the interpreter.

Let me know what you think of it.

----------------------------------------------------------------------

>Comment By: Michael Stone (mbrierst)
Date: 2003-01-29 18:19

Message:
Logged In: YES 
user_id=670441

Actually, the readline library does have the functionality to get the current binding of the tab key, so it could be saved and restored.  However, to do this in python some stuff would have to be added to the readline.c module, to create some python layer that deals with the way readline stores macros, functions, and keymaps.  It's probably not worth the effort unless someone wants to do major changes to the readline module to add the full functionality of the underlying library to the python interface. 

Probably cmd.py shouldn't be rebinding the tab key to complete at all.  If the user wants that, won't they have already done it somewhere else, like in their pythonrc or inputrc files?  And if they don't it might be impolite to change their bindings.

----------------------------------------------------------------------

Comment By: Michael Stone (mbrierst)
Date: 2003-01-29 15:27

Message:
Logged In: YES 
user_id=670441

I attached a changed readline.c patch to hopefully get rid of any "sickness".
(There was a not-checking-for-null problem too... ouch)

I think it's good now.  But note, there may not be a way to do this sort of thing perfectly.  If you mess around enough with starting debuggers within debuggers (or in general anything that uses a Cmd object) it might be possible to end up with an unexpected completer function in the end.

And it looks like under the current system there's no way to get back the completer key that was initially used.  But this isn't SUCH a big deal since I think everyone uses tab, right?

At any rate, the change is definitely an improvement for me.

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2003-01-29 10:36

Message:
Logged In: YES 
user_id=6656

I approve of this patch in principle.  I hadn't done enough
investigation to see that it was so easy to get the current
completer function!

OTOH:

return Py_BuildValue("O", completer);

is sick.  Change that to

Py_INCREF(completer);
return completer;

and if noone else howls, I'll check it in.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=676342&group_id=5470