Skip to content

rlcompleter should be enabled automatically #50095

Closed

Description

@cben
mannequin
BPO 5845
Nosy @loewis, @ronaldoussoren, @mdickinson, @cben, @jaraco, @abalkin, @pitrou, @larryhastings, @giampaolo, @ned-deily, @ezio-melotti, @merwok, @stevendaprano, @bitdancer, @florentx, @xdegaye, @serhiy-storchaka
Files
  • fix-5845.diff
  • c43e264256e4.diff
  • defaultreadline.patch
  • issue5845_osx_fix.patch
  • completer.py
  • completer.py
  • history.py
  • rl_history_guard.patch
  • 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']

    Activity

    1. cben commented on Apr 25, 2009

      cbenmannequin
      MannequinAuthor

      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!

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-featureA feature request or enhancement
      on Apr 25, 2009
    3. merwok commented on Apr 27, 2009

      @merwok
      Member

      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

    4. pitrou commented on Apr 27, 2009

      @pitrou
      Member

      He, adding completion is also something I find myself adding on every
      box on which I use Python...

    5. bitdancer commented on Dec 9, 2010

      @bitdancer
      Member

      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.

    6. merwok commented on Dec 9, 2010

      @merwok
      Member

      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?”)

    7. pitrou commented on Dec 9, 2010

      @pitrou
      Member

      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.

    8. added
      stdlibStandard Library Python modules in the Lib/ directory
      and removed
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      on Dec 9, 2010
    9. ned-deily commented on Dec 9, 2010

      @ned-deily
      Member

      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:

          import rlcompleter
          if 'libedit' in readline.__doc__:
              readline.parse_and_bind("bind ^I rl_complete")
          else:
              readline.parse_and_bind("tab: complete")

      See bpo-10666 for more details and some possible changes.

    10. ned-deily commented on Dec 9, 2010

      @ned-deily
      Member

      Nosying Martin: any Windows installer concerns?

    11. loewis commented on Dec 9, 2010

      loewismannequin
      Mannequin

      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.

    12. merwok commented on Mar 25, 2011

      @merwok
      Member

      Ned, does readline.read_init_file() with libedit?

    13. ned-deily commented on Mar 25, 2011

      @ned-deily
      Member

      readline.read_init_file() does work with libedit. The directives read have to be in libedit format.

    14. 49 remaining items

    15. pitrou commented on Sep 29, 2013

      @pitrou
      Member

      When a user is not aware of this new feature and has been implementing
      up to now her/his PYTHONSTARTUP file with the first example given in
      python 3.3 documentation at

      http://docs.python.org/3/library/readline.html?highlight=readline#example

      then each new interactive python 3.4 session reads (appending them)
      both history files which are saved on exit. Thus those files double
      their size after each interactive python 3.4 session and pretty soon
      become few mega bytes long with a python start up time that becomes
      quite noticeable.

      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.

    16. pitrou commented on Sep 29, 2013

      @pitrou
      Member

      Attaching patch to only load history file if no history exists.

    17. python-dev commented on Sep 29, 2013

      python-devmannequin
      Mannequin

      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

    18. xdegaye commented on Sep 29, 2013

      xdegayemannequin
      Mannequin

      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.

    19. pitrou commented on Sep 29, 2013

      @pitrou
      Member

      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.

      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.

    20. serhiy-storchaka commented on Dec 8, 2013

      @serhiy-storchaka
      Member

      What is the status of this issue?

    21. pitrou commented on Dec 8, 2013

      @pitrou
      Member

      I would say it's now closed. If there's some fine tuning needed, separate issues should be opened.

    22. jaraco commented on Jan 27, 2014

      @jaraco
      Member

      Added bpo-20411, revealed in 3.4b2.

    23. python-dev commented on Mar 9, 2014

      python-devmannequin
      Mannequin

      New changeset 69c451851c71 by R David Murray in branch 'default':
      whatsnew: sys.__interactivehook__. (bpo-5845)
      http://hg.python.org/cpython/rev/69c451851c71

    24. dabeaz commented on Apr 9, 2014

      dabeazmannequin
      Mannequin

      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:

      >>> for i in range(10):
      ...      print(i)

      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.

    25. bitdancer commented on Apr 12, 2014

      @bitdancer
      Member

      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.

    26. VictorVarvariuc commented on Jun 13, 2015

      VictorVarvariucmannequin
      Mannequin

      Here is the new issue (putting the link here for reference): http://bugs.python.org/issue22086

    27. bitdancer commented on Jun 13, 2015

      @bitdancer
      Member

      The active issue for this is now 23441.

    28. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      deferred-blockerstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions