<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">That looks pretty great.  I would use
      something like that.  <br>
      <br>
      For the filename('.txt'), it could be handy to be able to pass
      arbitrary globs (as in for glob.glob).  You could still default to
      matching against the end of the string for extensions, but adding
      the glob support costs little (since you probably want to use glob
      internally anyway.  <br>
      <br>
      For extra (and unnecessary) fancyness, I could also see use cases
      for <br>
      from from tablib import tabcompletion, instance<br>
      class bar:<br>
          pass<br>
      @tabcompletion(foo=instance(bar))<br>
      to be able to only complete for specific types of objects for
      other parameters (it would do an isinstance test).  <br>
      <br>
      Even more bonus points if the decorator could parse numpy styled
      docstrings to grab that kind of information about parameters.  I
      guess at this point you could do type checking, file existence
      checking, and a variety of other fun stuff there as well once you
      have that information, but that is almost certainly going out of
      the scope of your proposal.  <br>
      <br>
      Sorry if I am growing your proposal too much, the basic thing you
      proposed would still be very useful.  If I can grab some spare
      mental cycles, I would collaborate with you on it if you end up
      writing it.  <br>
      <br>
      Tom<br>
      <br>
      On 11/29/2012 05:28 AM, Robert McGibbon wrote:<br>
    </div>
    <blockquote
      cite="mid:669615BA-66DA-4CA6-8848-ED64BC4E3710@gmail.com"
      type="cite">
      <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><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; -webkit-nbsp-mode:
                space; -webkit-line-break: after-white-space; ">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 moz-do-not-send="true"
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 moz-do-not-send="true"
                          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 moz-do-not-send="true"
                            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
                            moz-do-not-send="true"
                            href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
                        </blockquote>
                        <blockquote type="cite"><a
                            moz-do-not-send="true"
                            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 moz-do-not-send="true"
                          href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
                        <a moz-do-not-send="true"
                          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 moz-do-not-send="true"
                href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
              <a class="moz-txt-link-freetext" href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
IPython-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a>
<a class="moz-txt-link-freetext" href="http://mail.scipy.org/mailman/listinfo/ipython-dev">http://mail.scipy.org/mailman/listinfo/ipython-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>