_ipython_key_completions_ has unexpected behaviour

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

_ipython_key_completions_ has unexpected behaviour

Ludwig Schwardt-2
Hi,

I am very excited about the new custom dict key completer as it potentially replaces many lines of brittle code in my libraries dating back to before IPython 0.10.

My excitement was tempered when I used it. The following happens on the latest master:

In [6]: class A(object):
   ...:     def _ipython_key_completions_(self):
   ...:         return ['x', 'y']
   ...:     

In [7]: 

In [7]: a = A()

In [8]: a['x
             x      %xmode 
             %xdel  xrange 

I expected the list of options to include only strings returned by _ipython_key_completions_ but instead it gives the whole shebang of filenames, Python keywords, magics, etc.

On inspection of the source it seems that all matchers are used unless a custom completer is registered (which is my current setup). Alternatively, the merge_completions=False config option will only return the results of the first successful matcher but since dict_key_matches is the last matcher this will also not help.

I would like dict_key_matches to be the only matcher if _ipython_key_completions_ is defined, without resorting to config overrides. Am I the only one? :-)

Thanks in advance,

Ludwig


_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: _ipython_key_completions_ has unexpected behaviour

Thomas Kluyver-2
The whole completion system is in dire need of an overhaul to make it more flexible. However, I don't think this is as problematic as it seems - tab completion is only useful with names of more than a couple of characters, and then the ambiguity will disppear rapidly.

On 27 July 2016 at 15:00, Ludwig Schwardt <[hidden email]> wrote:
Hi,

I am very excited about the new custom dict key completer as it potentially replaces many lines of brittle code in my libraries dating back to before IPython 0.10.

My excitement was tempered when I used it. The following happens on the latest master:

In [6]: class A(object):
   ...:     def _ipython_key_completions_(self):
   ...:         return ['x', 'y']
   ...:     

In [7]: 

In [7]: a = A()

In [8]: a['x
             x      %xmode 
             %xdel  xrange 

I expected the list of options to include only strings returned by _ipython_key_completions_ but instead it gives the whole shebang of filenames, Python keywords, magics, etc.

On inspection of the source it seems that all matchers are used unless a custom completer is registered (which is my current setup). Alternatively, the merge_completions=False config option will only return the results of the first successful matcher but since dict_key_matches is the last matcher this will also not help.

I would like dict_key_matches to be the only matcher if _ipython_key_completions_ is defined, without resorting to config overrides. Am I the only one? :-)

Thanks in advance,

Ludwig


_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev



_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: _ipython_key_completions_ has unexpected behaviour

Ludwig Schwardt-2
In reply to this post by Ludwig Schwardt-2
Hi,
 
The whole completion system is in dire need of an overhaul to make it more flexible. However, I don't think this is as problematic as it seems - tab completion is only useful with names of more than a couple of characters, and then the ambiguity will disppear rapidly.

Thanks for clearing that up. I guess I'll stick with the custom completers for now. You underestimate how lazy my typing has become with my finger on the TAB buzzer :-)

Regards,

Ludwig
 

_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev