How to find available arguments python built in classes via Emacs (elpy)

700 Views Asked by At

When I use emacs with elpy, just about every time I start writing code for function by typing:

foo_func(

I automatically get on the bottom window:

:container.foo_func(x, y, z=None)

But when I attempt on built-in type like enumerate or sort

enumerate(
list.sort(

I do not get that nice argument list in elpy. If not, then are there ways to get that even via writing a call like:

>dir(enumerate)
>inspect.signature(enumerate)

Appreciate any pointers in advance

2

There are 2 best solutions below

0
On

No, some built-in functions (implemented in C) do not provide the required metadata to create signatures for them. Some do (those that are converted to use Argument Clinic in CPython do), while others don't.

This is stated in inspect.signatures documentation, too:

Note: Some callables may not be introspectable in certain implementations of Python. For example, in CPython, some built-in functions defined in C provide no metadata about their arguments.

Case in point:

>>> signature(sorted)
<Signature (iterable, /, *, key=None, reverse=False)>
>>> signature(enumerate)
ValueError: no signature found for builtin type <class 'enumerate'>

So you'd need to consult the documentation for these (maybe an emacs plugin that uses the docs might exist?)

0
On

Thank u that helped above.

Elpy provides a single interface to documentation. C-c C-d (elpy-doc) When point is on a symbol, Elpy will try and find the documentation for that object, and display that. If it can’t find the documentation for whatever reason, it will try and look up the symbol at point in pydoc. If it’s not there, either, it will prompt the user for a string to look up in pydoc. With a prefix argument, Elpy will skip all the guessing and just prompt the user for a string to look up in pydoc.

enumerate( # & I hit C-c C-d

enumerate():

enumerate(iterable[, start]) -> iterator for index, value of iterable

Return an enumerate object. iterable must be another object that supports iteration. The enumerate object yields pairs containing a count (from start, which defaults to zero) and a value yielded by the iterable argument. enumerate is useful for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ...