From 32b9294f2a195686fd21b95817bf2a4b26314935 2019-06-27 04:39:46 From: Brandon T. Willard Date: 2019-06-27 04:39:46 Subject: [PATCH] Fix all_completions output for both Jedi and non-Jedi cases Closes #11802. --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index bc39dc3..e7bb0f8 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -1139,10 +1139,10 @@ class IPCompleter(Completer): """ Wrapper around the completion methods for the benefit of emacs. """ - prefix = text[:text.rfind(".") + 1] + prefix = text.rpartition('.')[0] with provisionalcompleter(): - return list(map(lambda c: prefix + c.text, - self.completions(text, len(text)))) + return ['.'.join([prefix, c.text]) if prefix and self.use_jedi else c.text + for c in self.completions(text, len(text))] return self.complete(text)[1] diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index 772cefc..d364d1c 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -346,6 +346,24 @@ class TestCompleter(unittest.TestCase): )[1] nt.assert_equal(c, [escaped]) + def test_all_completions_dups(self): + """ + Make sure the output of `IPCompleter.all_completions` does not have + duplicated prefixes. + """ + ip = get_ipython() + c = ip.Completer + ip.ex("class TestClass():\n\ta=1\n\ta1=2") + for jedi_status in [True, False]: + with provisionalcompleter(): + ip.Completer.use_jedi = jedi_status + matches = c.all_completions("TestCl") + assert matches == ['TestClass'], jedi_status + matches = c.all_completions("TestClass.") + assert len(matches) > 2, jedi_status + matches = c.all_completions("TestClass.a") + assert matches == ['TestClass.a', 'TestClass.a1'], jedi_status + def test_jedi(self): """ A couple of issue we had with Jedi