Re: add tab completion for arguments dynamically

Matthias Bussonnier <[email protected]> Thu, 2 Mar 2017 13:25:33 -0800
Newsgroups gmane.comp.python.ipython.devel
Message-ID <CANJQusUbWbMntsnHNLzMof5Ck1RGBn90UwNKN92qAtdP1LyLKg@mail.gmail.com>
Hi Glenn,

You can set the `__signature__` of your object. likely possible with a
decorator.
Here is a short example of how you could do it in a REPL.


In [21]: from inspect import Signature, Parameter

In [22]: def foo(*kwargs):
    ...:     pass

In [23]: foo?
Signature: foo(*kwargs)
Docstring: <no docstring>
File:      ~/dev/docathon/<ipython-input-22-086da1400d07>
Type:      function

In [24]: foo.__signature__ = Signature(parameters={Parameter('a',
Parameter.POSITIONAL_OR_KEYWORD):None})

In [25]: foo?
Signature: foo(a)
Docstring: <no docstring>
File:      ~/dev/docathon/<ipython-input-22-086da1400d07>
Type:      function


That should  not only work with IPython, but with anything that use
the Python inspect library.

Note that what I do above is imperfect as you should use an
OrderedDict instead of a dict for `parameters=...`

Does that helps ?

-- 
M


On Thu, Mar 2, 2017 at 12:58 PM, G Jones <[email protected]> wrote:
> Hi,
> Is it possible to customize the completion list when typing keyword
> arguments?
> For example suppose I have a function like:
> def myfunc(**kwargs):
>     val = kwargs['val']
>
> is there a way to tell ipython that when it sees me type:
> myfunc(va<tab>
>
> it suggests "val="?
>
> Thanks,
> Glenn
>
>
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.scipy.org/mailman/listinfo/ipython-dev
>