Repository navigation
rlcompleter should be enabled automatically #50095
Copy link
Copy link
Closed
Labels
deferred-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2013-12-08.19:18:07.030>
created_at = <Date 2009-04-25.23:27:18.758>
labels = ['deferred-blocker', 'type-feature', 'library']
title = 'rlcompleter should be enabled automatically'
updated_at = <Date 2015-06-13.20:09:00.871>
user = 'https://github.com/cben'bugs.python.org fields:
activity = <Date 2015-06-13.20:09:00.871>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2013-12-08.19:18:07.030>
closer = 'pitrou'
components = ['Library (Lib)']
creation = <Date 2009-04-25.23:27:18.758>
creator = 'cben'
dependencies = []
files = ['22936', '30098', '30099', '30148', '30149', '31095', '31096', '31914']
hgrepos = ['9']
issue_num = 5845
keywords = ['patch']
message_count = 66.0
messages = ['86570', '86632', '86660', '123696', '123697', '123698', '123703', '123705', '123709', '132117', '132120', '132158', '142371', '142393', '142395', '143548', '143554', '143608', '143609', '143618', '143621', '143961', '188241', '188385', '188386', '188505', '188511', '188517', '188521', '188523', '188524', '188525', '188532', '188533', '188534', '188535', '188540', '188542', '188543', '188549', '188552', '188553', '188555', '188557', '188560', '188589', '188592', '193981', '193986', '194006', '194010', '194427', '198636', '198640', '198642', '198645', '198648', '198653', '205569', '205595', '209472', '212972', '215784', '215975', '245325', '245328']
nosy_count = 23.0
nosy_names = ['loewis', 'ronaldoussoren', 'mark.dickinson', 'cben', 'jaraco', 'belopolsky', 'pitrou', 'larry', 'techtonik', 'giampaolo.rodola', 'ned.deily', 'ezio.melotti', 'eric.araujo', 'steven.daprano', 'r.david.murray', 'flox', 'dabeaz', 'lesmana', 'xdegaye', 'tshepang', 'python-dev', 'serhiy.storchaka', 'Victor.Varvariuc']
pr_nums = []
priority = 'deferred blocker'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue5845'
versions = ['Python 3.4']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
deferred-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Activity
cben commentedon Apr 25, 2009
An interactive prompt should offer working completion out-of-the-box,
without requiring every Python user on earth to create a $PYTHONSTARTUP
with '''import readline; readline.parse_and_bind("tab: complete")'''.
Note that it should work not only when Python is run without arguments,
but also when running with the -i option.
And ideally, it should only install the completion function when
dropping to the interpreter, not from the start, so that code that runs
before dropping to the interpreter is not affected. But this is really
not important.
Safety: if 'rlcompleter' or 'readline' are not availiable (e.g. broken
python install), the user must still get a working interpreter, just
without completion.
Portability: there won't be completion on windows (as long as pyreadline
or similar is not part of Python). But that shouldn't delay unix support!
merwok commentedon Apr 27, 2009
What would be the right place for this to happen? I first thought of
site.py, but -S would then turn off readline support. Does it have to be
done somewhere in C land?
But perhaps tab isn’t the right key to bind. I think inputrc could set
it to something different, perhaps shell rc files too. Is there an API
to get this setting, does readline.so already do the right thing, or
does it have to be added?
Moreover, in my PYTHONSTARTUP I not only bind tab to complete, but also
set a history file. Should this be automatic too? UNIX rules would
suggest a standard ~/.pyhistory file, or we could follow newer
freedesktop.org specifications [1].
So, I don’t know the history and choices behind readline.so, but from a
user point of view, being fed up with lack of tab completion finally had
me put up a PYTHONSTARTUP file with these settings, and then some useful
functions, and so on. This lack of completion was ultimately a good
thing for me. Still, completion could be made to work out of the box,
and the man page could link to the doc explaining how to customize this
behavior.
[1] XDG Base Directory Specification:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
Cheers, Merwok
pitrou commentedon Apr 27, 2009
He, adding completion is also something I find myself adding on every
box on which I use Python...
bitdancer commentedon Dec 9, 2010
for what it is worth, I am +1 on having completion and history file work by default. The sqlite3 command line does this, for example. I think it is what unix user expect nowadays, and I think it is reasonable.
Looking at my home directory, it would appear that the de-facto standard history file name would be .python_history. This is based on .mysql_history, .psql_history, and .sqlite_history, none of which I configured explicitly to support history saving.
merwok commentedon Dec 9, 2010
Okay, that’s one question answered. Still to solve: How to bind the right key? (“But perhaps tab isn’t the right key to bind. I think inputrc could set it to something different, perhaps shell rc files too. Is there an API to get this setting, does readline.so already do the right thing, or does it have to be added?”)
pitrou commentedon Dec 9, 2010
I think TAB is the key expected by most people, so let's make it the default.
As for the location, site.py is an adequate one IMO.
ned-deily commentedon Dec 9, 2010
Keep in mind that the Python readline module may be linked to either GNU readline or the BSD editline (libedit) library and they have different command strings. Note the warning here:
http://docs.python.org/dev/py3k/library/readline.html
Here's a snippet of what I have today in my startup file:
See bpo-10666 for more details and some possible changes.
ned-deily commentedon Dec 9, 2010
Nosying Martin: any Windows installer concerns?
loewis commentedon Dec 9, 2010
There is no readline support on Windows at all, so I don't think the Windows installer can be affected. I'm uncertain what the proposed change to Python is at this point, though.
merwok commentedon Mar 25, 2011
Ned, does readline.read_init_file() with libedit?
ned-deily commentedon Mar 25, 2011
readline.read_init_file() does work with libedit. The directives read have to be in libedit format.
49 remaining items
pitrou commentedon Sep 29, 2013
Interesting. A way to avoid doing this would be to only load history if
no history is already present. Since the sys.__interactivehook__ is
executed after PYTHONSTARTUP, this would allow the latter to take
precedence.
pitrou commentedon Sep 29, 2013
Attaching patch to only load history file if no history exists.
python-dev commentedon Sep 29, 2013
New changeset 687dd81cee3b by Antoine Pitrou in branch 'default':
Issue bpo-5845: In site.py, only load readline history from ~/.python_history if no history has been read already. This avoids double writes to the history file at shutdown.
http://hg.python.org/cpython/rev/687dd81cee3b
xdegaye commentedon Sep 29, 2013
The patch fixes the problem on my setup. A very minor glitch: after
manually emptying or removing the PYTHONSTARTUP history file, the
history is loaded with the content of ~/.python_history on the next
session.
pitrou commentedon Sep 29, 2013
Yes, the only way to know if a history file has already been loaded with
readline seems to be to query the history itself. So, if the history is
empty, we consider no file has been loaded.
serhiy-storchaka commentedon Dec 8, 2013
What is the status of this issue?
pitrou commentedon Dec 8, 2013
I would say it's now closed. If there's some fine tuning needed, separate issues should be opened.
jaraco commentedon Jan 27, 2014
Added bpo-20411, revealed in 3.4b2.
python-dev commentedon Mar 9, 2014
New changeset 69c451851c71 by R David Murray in branch 'default':
whatsnew: sys.__interactivehook__. (bpo-5845)
http://hg.python.org/cpython/rev/69c451851c71
dabeaz commentedon Apr 9, 2014
Funny thing, this feature breaks the interactive interpreter in the most basic way on OS X systems. For example, the tab key won't even work to indent. You can't even type the most basic programs into the interactive interpreter. For example:
Oh sure, you can make it work by typing the space bar a bunch of times, but it's extremely annoying.
The only way I was able to get a working interactive interpreter on my machine was to manually edit site.py and remove the call to enablerlcompleter() from main().
I hope someone reconsiders this feature and removes it as default behavior.
bitdancer commentedon Apr 12, 2014
This issue should have gone back to being a release blocker after the alpha release to fix the tab-as-indent issue, but obviously that didn't happen (I forgot about it myself). Please open a new issue requesting a fix for this bug (that tab doesn't work as indent at the ... prompt), referencing the discussion in this issue.
VictorVarvariuc commentedon Jun 13, 2015
Here is the new issue (putting the link here for reference): http://bugs.python.org/issue22086
bitdancer commentedon Jun 13, 2015
The active issue for this is now 23441.