[pypy-issue] [issue950] startup_hook in readline

hpaulj tracker at bugs.pypy.org
Fri Dec 2 08:02:56 CET 2011

New submission from hpaulj <hpj3 at myuw.net>:

Ipython running under pypy (1.6) does not autoindent or 'rep'.  The problem is 
with pypy readline.raw_input.  It calls startup_hook before the reader.buffer is
reset (by read.prepare).  Since a typical action of startup_hook is to write 
something to this buffer (via readline.insert_text), this is lost when the 
buffer is cleared in reader.readline().  The PyMOTW readline_hooks.py script is 
a simple way to test this action.

A solution is to pass self.startup_hook as an optional argument to 
reader.readline, and execute it at the start of the try block (before refresh).
This moves its action after the reader.prepare action.

The PyMOTW script reveals another bug.  reader.insert() gives an AttributeError 
if self.pos has not been initialized.  This can happen with the current position 
of the startup_hook (before reader.prepare).  It shouldn't happen with my 
suggested change, but it still would be a good idea to test for self.pos in 


Pypy does not implement pre_input_hook, but ipython does not use that.

messages: 3528
nosy: hpaulj, pypy-issue
priority: bug
status: unread
title: startup_hook in readline

PyPy bug tracker <tracker at bugs.pypy.org>

More information about the pypy-issue mailing list