Greedy completer

By vivainio

Every now and again, we at IPython0 get complaints about the strict criteria that we use for tab completing python attributes; basically, we only tab complete expressions where side effects are not likely when calling ‘eval’, as in expression foo.bar.ba<TAB> (we eval foo.bar, then get attributes from the resulting object). An expression we do not eval is foo(12).bar.ba + TAB, because calling foo(12) may do something nasty that the innocent ipythoneer may not be aware of.

Until now, that is. Sometimes all you care about is convenience – maybe your interactive work is not so side-effect-sensitive, maybe you trust yourself enough to not press tab after a dangerous command, or maybe you just enjoy living on the edge. I just added ipy_greedycompleter.py IPython extension to the trunk, which does not really care about what it evaluates – pressing TAB is enough, and if something breaks, the user gets to keep both pieces.

Activate it by typing “import ipy_greedycompleter” (or “import ipy_gr” + TAB for completion savvy), or add it to you ipy_user_conf.py.

I should probably also mention that you can get IPython trunk (it’s probably stabler than 0.8.2 at this point) from launchpad by doing:

bzr branch lp:ipython

– Ville

Tags:

2 Responses to “Greedy completer”

  1. Michael Says:

    Sounds extremely cool!
    I always missed being able to autocomplete on sequences. Wouldn’t it be safe to evaluate things like “some_list[15]. +TAB”? If so, would a less greedy completer that works on sequences but leaves function calls aside be an option?

  2. vivainio Says:

    We can never be sure what exactly is “safe”, indexing can cause side effects as well (though it’s not quite so probable).

    It could be an option to provide a little bit more safety, it’s rather simple – just edit the regexp in ipy_greedycompleter.py. But, I think we can leave this as it is now, and leave the responsibility for the user (erring on the side of power than safety, for the users that want it).

Leave a Reply