Open vaaaaanquish opened 4 years ago
Hi @vaaaaanquish,
I just read the issue only now. As I suggested in the PR, testing the length in the condition is the right thing to do, because it means that if at some point the condition is not satisfied, the key binding engine can possibly call another handler.
On top of this, I would actually also add the except StopIteration: pass
. Just in case we would ever call this key binding handler from somewhere else, with a different condition. (even if it's unlikely.)
We would need two PRs. One against the 2.0 branch and one against the master branch.
@jonathanslenders Thanks.
We would need two PRs. One against the 2.0 branch and one against the master branch.
I understood, I'll do it :)
Hi. Thanks.
What's issue
I got
Unhandled exception in event loop
error in this keybinding function. https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/bindings/auto_suggest.py#L49Environment
OS X python 3.6.8 prompt-toolkit == 2.0.9 or 3.0.0
How reproduction
using this sample: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/examples/prompts/auto-suggestion.py
Solution
Because generator raises
StopIteration
. We use suggestion_available filter, butapp.current_buffer.suggestion
becomes None orSuggestion()
. It can't catch exception. https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/bindings/auto_suggest.py#L31We can use
try/except
orSuggestion.__len__
.A: try/except
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/bindings/auto_suggest.py#L49
B: Suggestion.__len__
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/auto_suggest.py#L48
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/bindings/auto_suggest.py#L31
Comment
I think Solution B is better:)