Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all_completions returns nothing (simple fix suggested) #11541

Closed
memeplex opened this issue Jan 2, 2019 · 6 comments · Fixed by #11591
Closed

all_completions returns nothing (simple fix suggested) #11541

memeplex opened this issue Jan 2, 2019 · 6 comments · Fixed by #11591
Milestone

Comments

@memeplex
Copy link
Contributor

memeplex commented Jan 2, 2019

The Completer.all_completions method, which emacs python.el and elpy mode use, is returning nothing defined in the current scope. For example:

In [87]: xxx = 2

In [91]: get_ipython().Completer.all_completions('x')
Out[91]: ['%xdel', '%xmode']

In [92]: get_ipython().Completer.all_completions('xx')
Out[92]: []

Internally it's using jedi but discarding jedi completions. Now, all_completions calls the deprecated complete instead of completions. A simple change fixes both the usage of a deprecated method and a bug:

In [127]: list(map(lambda c: c.text, get_ipython().Completer.completions('x', len('x'))))
Out[127]: ['xxx', '%xdel', '%xmode']

Why not redefining all_completions like that? At least the following is working for me inside an emacs inferior python session:

get_ipython().Completer.all_completions = lambda t: map(lambda c: c.text, get_ipython().Completer.completions(t, len(t)))
@memeplex
Copy link
Contributor Author

memeplex commented Jan 2, 2019

I realized the map is slightly more complicated because of a mismatch between what is returned and what emacs expects:

lambda c: t + c.text if t.endswith(".") else c.text

This way argp -> argparse but argparse. -> argparse.ArgumentError.

@memeplex
Copy link
Contributor Author

memeplex commented Jan 2, 2019

Sorry, this one seems to be the right fix: lambda c: t[:t.rfind(".") + 1] + c.text

  • argp -> argparse
  • argparse. -> argparse.ArgumentError
  • argparse.Arg -> argparse.ArgumentError

It's probably better to first compute t[:t.rfind(".") + 1] once and then do the mapping, I wrote it this way instead because it's a dirty hack I'm adding to exec_lines for now.

@memeplex
Copy link
Contributor Author

@Carreau would you consider adding this to the next milestone? It's easy to fix and it's really critical for emacs users. Thanks!

@Carreau Carreau added this to the 7.3 milestone Jan 29, 2019
@Carreau
Copy link
Member

Carreau commented Jan 29, 2019

Sure, sending a PR would help. I'm way behind on working on IPython.

@memeplex
Copy link
Contributor Author

memeplex commented Feb 4, 2019

@Carreau check the PR above, please.

@memeplex
Copy link
Contributor Author

Can we close this? The fix has already been merged.

@Carreau Carreau removed this from the 7.3 milestone Feb 18, 2019
@Carreau Carreau added this to the 7.3 milestone Mar 21, 2019
LucianaMarques pushed a commit to LucianaMarques/ipython that referenced this issue Apr 28, 2019
This fixes a bug affecting emacs users introduced by 7.2.

Fixes ipython#11541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants