<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Nov 29, 2012, at 3:28 AM, Robert McGibbon <<a href="mailto:rmcgibbo@gmail.com">rmcgibbo@gmail.com</a>> wrote:</div>
<div><br></div><blockquote type="cite"><div><div>Hi,</div><div><br></div>Good spot, Matthias. I didn't see that method was already exposed -- I was just looking at IPCompleter.matchers, which what that method inserts into.<div>
<div><br></div><div>Annotations are cool, but they're not obviously composable. I worry that if I use them for this and then fix one syntax of how the annotation is parsed, and somebody else</div><div>is using annotations in their lib for something else, the two schemes won't be able to interoperate. Also they're py3k only.</div>
</div></div></blockquote><div><br></div>Annotations syntax is python 3 only, but other than that, anyone can modify an object's __annotations__ dict. <div><br></div><div>Also, note that annotations don't have to be strings. They can be arbitrary objects. So what I would do is create completer template objects (e.g., there would be a FileCompleter for your example), and annotate with those. To compose, just make these objects in such a way that they are easily composable (or just annotate with a list of such objects, and append to the list of you want to add more). </div>
<div><br></div><div>Aaron Meurer</div><div><br><blockquote type="cite"><div><div><div><br></div><div>My preferred syntax would be</div><div><br></div><div>from tablib import tabcompletion, filename,</div><div><br></div><div>
@tabcompletion(fname=filename, mode=['r', 'w'])</div><div>def load(fname, mode, other_argument):</div><div>    pass</div><div><br></div><div>or maybe with a parameterized filename to get specific extensions</div>
<div><br></div><div>@tabcompletion(fname=filename('.txt'))</div><div>def f(fname, other_argument):</div><div>    pass</div><div><br></div><div>Is this something that other people would be interested in?</div><div>
<br></div><div>-Robert</div><div><br></div><div><div><div>On Nov 29, 2012, at 2:02 AM, Matthias BUSSONNIER wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap:break-word">Hi, <div>
<br></div><div>I may be wrong, but IIRC you can insert your own completer in the IPython  completer chain and decide to filter the previous completion.</div><div><br></div><div>You should be able to have a custom completer that just forward the previous completion in most cases, </div>
<div>And just do a dir completion if the object is np.loadtxt in your case (or look at __annotations__ if you wish).</div><div><br></div><div>I've found one reference to inserting custom completer here</div><div><a href="http://ipython.org/ipython-doc/dev/api/generated/IPython.core.interactiveshell.html?highlight=interactiveshell#IPython.core.interactiveshell.InteractiveShell.set_custom_completer">http://ipython.org/ipython-doc/dev/api/generated/IPython.core.interactiveshell.html?highlight=interactiveshell#IPython.core.interactiveshell.InteractiveShell.set_custom_completer</a></div>
<div><br></div><div><br></div><div>-- </div><div>Matthias</div><div><br><div><div>Le 29 nov. 2012 à 10:27, Aaron Meurer a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I've often thought this as well.  Probably a full-blown IPEP is in<br>
order here.  Perhaps __annotations__ would be the correct way to go<br>here.<br><br>Aaron Meurer<br><br>On Thu, Nov 29, 2012 at 12:58 AM, Robert McGibbon <<a href="mailto:rmcgibbo@gmail.com">rmcgibbo@gmail.com</a>> wrote:<br>
<blockquote type="cite">Hey,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Tab completion in IPython is one of the things that makes it so useful,<br></blockquote><blockquote type="cite">
especially the context specific tab completion for things like "from ..."<br></blockquote><blockquote type="cite">where only packages, or obviously the special completion for attributes when<br></blockquote><blockquote type="cite">
the line contains a dot.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I use IPython for interactive data analysis a lot, and one of the most<br></blockquote><blockquote type="cite">frequent operations is loading up data with something like numpy.loadtxt()<br>
</blockquote><blockquote type="cite">or various related functions.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">It would be really awesome if we could annotate functions to interact with<br>
</blockquote><blockquote type="cite">the tab completion system, perhaps for instance saying that argument 0 to<br></blockquote><blockquote type="cite">numpy.loadtxt() is supposed to be a filename, so let's give tab-complete<br>
</blockquote><blockquote type="cite">suggestions that try to look for directories/files. Some functions only<br></blockquote><blockquote type="cite">files with specific extensions, so you could filter based on that or<br>
</blockquote><blockquote type="cite">whatever.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">By hacking on the code for completerlib.py:cd_completer, I sketched out a<br></blockquote><blockquote type="cite">
little demo of what you could do with this: <a href="https://gist.github.com/4167151">https://gist.github.com/4167151</a>.<br></blockquote><blockquote type="cite">The architecture is totally wrong, but it lets you get behavior like:<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">```<br></blockquote><blockquote type="cite">In [1]: ls<br></blockquote><blockquote type="cite">datfile.dat  dir1/        dir2/        file.gz      random_junk  test.py<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In [2]: directory_as_a_variable = 'sdfsfsd'<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In [3]: f = np.loadtxt(<TAB><br>
</blockquote><blockquote type="cite">datfile.dat  dir1/        dir2/        file.gz<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In [4]: normal_function(<TAB><br></blockquote><blockquote type="cite">
Display all 330 possibilities? (y or n)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In [5]: g = np.loadtxt(di<TAB><br></blockquote><blockquote type="cite">dict                      dir1/                     directory_as_a_variable<br>
</blockquote><blockquote type="cite">divmod<br></blockquote><blockquote type="cite">dir                       dir2/                     directory_of_my_choosing<br></blockquote><blockquote type="cite">```<br></blockquote>
<blockquote type="cite"><br></blockquote><blockquote type="cite">Basically hitting the tab completion, when np.loadtxt is on the input line,<br></blockquote><blockquote type="cite">only shows directories and files that end with a certain extension. If you<br>
</blockquote><blockquote type="cite">start to type in the name of an object in your namespace, it'll show up too,<br></blockquote><blockquote type="cite">but only once you've typed in more than 1 matching character.<br>
</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The implementation in my gist is pretty lame. The way I've coded it up, the<br></blockquote><blockquote type="cite">special behavior is based on simply finding the string "np.loadtxt" on the<br>
</blockquote><blockquote type="cite">input line, not on the actual function. This means you can't really make the<br></blockquote><blockquote type="cite">behavior specific to your position in the argument list (i.e. I know that<br>
</blockquote><blockquote type="cite">the first arg is a filename, and so should be tab completed like this, but<br></blockquote><blockquote type="cite">the other ones are not). I suspect the right way to do the implementation is<br>
</blockquote><blockquote type="cite">via function decorators to specify the behavior and then adding to<br></blockquote><blockquote type="cite">IPCompleter instead.<br></blockquote><blockquote type="cite"><br></blockquote>
<blockquote type="cite">I think I'm up for giving this a shot.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thoughts? Is this a feature anyone else would find interesting?<br></blockquote>
<blockquote type="cite"><br></blockquote><blockquote type="cite">-Robert<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">
_______________________________________________<br></blockquote><blockquote type="cite">IPython-dev mailing list<br></blockquote><blockquote type="cite"><a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
</blockquote><blockquote type="cite"><a href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br></blockquote><blockquote type="cite"><br></blockquote>_______________________________________________<br>
IPython-dev mailing list<br><a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br><a href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br></div>
</blockquote></div><br></div></div>_______________________________________________<br>IPython-dev mailing list<br><a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br><a href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</blockquote></div><br></div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>IPython-dev mailing list</span><br><span><a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a></span><br>
<span><a href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a></span><br></div></blockquote></div></body></html>