prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 718 forks source link

Multiple tab completions triggers traceback #690

Open melund opened 5 years ago

melund commented 5 years ago

In xonsh we experience an issue where pressing tab many times for tab completions can trigger the following traceback (https://github.com/xonsh/xonsh/issues/2730):

@scopatz can confirm that this also happens for Linux.

Unhandled exception in event loop:
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\eventloop\win32.py", line 102, in _run_task
    t()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\eventloop\context.py", line 115, in new_func
    return func(*a, **kw)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\application\application.py", line 548, in read_from_input
    self.key_processor.process_keys()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 272, in process_keys
    self._process_coroutine.send(key_press)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 179, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 321, in _call_handler
    handler.call(event)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\key_binding\key_bindings.py", line 78, in call
    return self.handler(event)
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\ptk2\key_bindings.py", line 369, in generate_completions
    second_tab()
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\ptk2\key_bindings.py", line 362, in second_tab
    b.complete_next()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\buffer.py", line 758, in complete_next
    self.go_to_completion(index)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\buffer.py", line 848, in go_to_completion
    new_text, new_cursor_position = state.new_text_and_position()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\buffer.py", line 93, in new_text_and_position
    c = self.completions[self.complete_index]

Exception list index out of range

If I press only a few times followed by a ctrl-c I get slightly different traceback:

snail@sea ~\Documents\xo        ig_styles
$ not_a_thing.Traceback (most recent call last):
  File "C:\Users\mel\anaconda3\Scripts\xonsh-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\main.py", line 344, in main
    _failback_to_other_shells(args, err)
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\main.py", line 313, in _failback_to_other_shells
    raise err
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\main.py", line 342, in main
    return main_xonsh(args)
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\main.py", line 368, in main_xonsh
    shell.shell.cmdloop()
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\ptk2\shell.py", line 160, in cmdloop
    line = self.singleline(auto_suggest=auto_suggest)
  File "C:\Users\mel\anaconda3\lib\site-packages\xonsh\ptk2\shell.py", line 126, in singleline
    line = self.prompter.prompt(**prompt_args)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 722, in prompt
    return run_sync()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 706, in run_sync
    return self.app.run(inputhook=self.inputhook)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\application\application.py", line 682, in run
    return run()
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\application\application.py", line 654, in run
    f = self.run_async(pre_run=pre_run)
  File "C:\Users\mel\anaconda3\lib\site-packages\prompt_toolkit\application\application.py", line 513, in run_async
    assert not self._is_running
AssertionError

We are using prompt_toolkit 2.0.3

scopatz commented 5 years ago

Oh sorry! slight correction. I can confirm that this does not happen on Linux

melund commented 5 years ago

Ups. Sorry. I misread it.

jonathanslenders commented 5 years ago

Does it happen on OS X too? Or only on Windows?

melund commented 5 years ago

I don't know. I have no way of testing it on osx, but we haven't heard from anyone having a similar problem.

melund commented 5 years ago

@Achimh3011 reported an other problem with the newest version of xonsh recently and he was using osx.

@Achimh3011 have you experienced something like this on your setup?

Achimh3011 commented 5 years ago

No, I don't have that problem on OS X.

I do have tracebacks specifically with tab completion for docker (xonsh-docker-tabcomplete package). But I have not even checked yet whether that's simply due to a misconfiguration on my machine.

sighingnow commented 5 years ago

Just FYI: the exception Exception list index out of range occurs on windows 10 with Python 3.7.2. But in my case it only occurs at the first time when I open ipython, import some library and press Tab. After exiting ipython and reopen ipython again, the problem disappear.

meereeum commented 5 years ago

Oh sorry! slight correction. I can confirm that this does not happen on Linux

I regularly experience this problem on Debian stretch with Python 3.7