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

SourceForge.net noreply@sourceforge.net
Mon, 03 Feb 2003 03:11:13 -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: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Michael Stone (mbrierst)
>Assigned to: Michael Hudson (mwh)
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 Hudson (mwh)
Date: 2003-02-03 11:11

Message:
Logged In: YES 
user_id=6656

Checked in as 

Lib/cmd.py revision 1.34

Thanks!  You probably didn't need to attach the patch three
times, though :-)

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

Comment By: Michael Stone (mbrierst)
Date: 2003-02-01 06:41

Message:
Logged In: YES 
user_id=670441

I started using the latest cvs version today.
I have attached a diff to the latest cvs as patchcmd2 if that's
more convenient for you to apply.

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

Comment By: Michael Stone (mbrierst)
Date: 2003-02-01 06:37

Message:
Logged In: YES 
user_id=670441

I started using the latest cvs version today.
I have attached a diff to the latest cvs as patchcmd2 if that's
more convenient for you to apply.

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

Comment By: Michael Stone (mbrierst)
Date: 2003-01-31 21:25

Message:
Logged In: YES 
user_id=670441

I started using the latest cvs version today.
I have attached a diff to the latest cvs as patchcmd2 if that's
more convenient for you to apply.

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

Comment By: Michael Stone (mbrierst)
Date: 2003-01-30 16:59

Message:
Logged In: YES 
user_id=670441

That sounds good to me.  Go ahead and check in patchcmd.

Thanks for your suggestions, I will follow them in future patches.  In this one, I was trying to follow the conventions I saw being used in the module, but they were outdated or incorrect (and I didn't always follow them correctly anyway!).  Okay that's definitely enough commentary for a few line patch.

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

Comment By: Michael Hudson (mwh)
Date: 2003-01-30 10:22

Message:
Logged In: YES 
user_id=6656

Thanks for the new patch, it looks OK.  There are a couple
of things that spring to mind for future patches: 

- the function should be METH_NOARGS (or you should check
the args tuple)

- there should be a blank line between the argspec line in
the docstring and the description

- you should use the PyDoc_STRVAR macro (but this was only
used in the CVS trunk's version of readline).

I made these changes and checked in revision 2.59 of
Modules/readline.c.

Wrt the cmd.py changes, I think I'll probably let that
sleeping dog lie.  I agree with you in general: cmd.py
probably shouldn't be rebinding any keys, but

1) the interface is "specify the completion key to get
completion",   so backwards compatibility raises its head

2) as you say, most people do probably rebind tab anyway

so I propose to check in your patchcmd, close the bug and
wait for someone to submit a bug report about pdb messing up
their bindings.

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

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