ipython / ipython/ipython

Completion of keyword arguments includes arguments from other functions whose names start with the function being completed

Open
#11,322 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

For example:

![screen shot 2018-09-19 at 00 29 42](https://user-images.githubusercontent.com/3627481/45720207-ae1d0180-bba3-11e8-9df7-04a615bee805.png)

Because `bar_more` starts with `bar`, the completer suggests the keyword arguments of `bar_more`, namely `spam`, which is not a valid argument for `bar`.

The relevant code is [here](https://github.com/ipython/ipython/blob/381c2039723a597eda9679d8f072d075e55c8501/IPython/core/completer.py#L1541-L1558). Specifically:

```python
callableMatches = self.global_matches(ids[0])
```

makes `callableMatches == ['bar', 'bar_more']`, and then arguments are fetched from each match:

```python
for callableMatch in callableMatches:
try:
namedArgs = self._default_arguments(eval(callableMatch,
self.namespace))
```

It's as if it's trying to complete the function name at the same time as the argument, but that makes no sense to me and nothing of the sort ever happens. Am I missing something?

Here's a real case using matplotlib:

![screen shot 2018-09-19 at 00 40 53](https://user-images.githubusercontent.com/3627481/45720498-c7727d80-bba4-11e8-8523-288c358c1edb.png)

The signature of [`plot`](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html) is just `(*args, **kwargs)`. The arguments suggested come from [`plot_date`](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot_date.html) and [`plotfile`](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plotfile.html). `plot` will actually accept arbitrary arguments without complaining, but I think it's safe to assume at least some of these suggestions are meaningless.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.