ipython / ipython/ipython

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

Offen
#11,322 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
16.8k
Forks
4.5k
Ø Merge
1 T. 2 Std.
Gemergte PRs (30 T.)
6

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.