[IPython-dev] _ipython_key_completions_ has unexpected behaviour

Ludwig Schwardt ludwig.schwardt at gmail.com
Wed Jul 27 10:00:22 EDT 2016


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,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20160727/3284d373/attachment.html>

More information about the IPython-dev mailing list