Skip to content

Commit 599cfea

Browse files
fix parameter name completion
1 parent 404e5c7 commit 599cfea

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

bpython/autocomplete.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ def format(self, word):
160160
return self._completers[0].format(word)
161161

162162
def matches(self, cursor_offset, line, **kwargs):
163+
return_value = None
163164
all_matches = set()
164165
for completer in self._completers:
165-
# these have to be explicitely listed to deal with the different
166-
# signatures of various matches() methods of completers
167166
matches = completer.matches(cursor_offset=cursor_offset,
168167
line=line,
169168
**kwargs)
170169
if matches is not None:
171170
all_matches.update(matches)
171+
return_value = all_matches
172172

173-
return all_matches
173+
return return_value
174174

175175

176176
class ImportCompletion(BaseCompletionType):
@@ -634,11 +634,11 @@ def get_default_completer(mode=SIMPLE):
634634
FilenameCompletion(mode=mode),
635635
MagicMethodCompletion(mode=mode),
636636
MultilineJediCompletion(mode=mode),
637-
GlobalCompletion(mode=mode),
638-
ArrayItemMembersCompletion(mode=mode),
639-
CumulativeCompleter((AttrCompletion(mode=mode),
637+
CumulativeCompleter((GlobalCompletion(mode=mode),
640638
ParameterNameCompletion(mode=mode)),
641-
mode=mode)
639+
mode=mode),
640+
ArrayItemMembersCompletion(mode=mode),
641+
AttrCompletion(mode=mode),
642642
)
643643

644644

bpython/test/test_autocomplete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def test_one_empty_completer_returns_empty(self):
107107
cumulative = autocomplete.CumulativeCompleter([a])
108108
self.assertEqual(cumulative.matches(3, 'abc'), set())
109109

110-
def test_one_none_completer_returns_empty(self):
110+
def test_one_none_completer_returns_none(self):
111111
a = self.completer(None)
112112
cumulative = autocomplete.CumulativeCompleter([a])
113-
self.assertEqual(cumulative.matches(3, 'abc'), set())
113+
self.assertEqual(cumulative.matches(3, 'abc'), None)
114114

115115
def test_two_completers_get_both(self):
116116
a = self.completer(['a'])

bpython/test/test_repl.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def test_fuzzy_attribute_complete(self):
383383
self.assertTrue(hasattr(self.repl.matches_iter, 'matches'))
384384
self.assertEqual(self.repl.matches_iter.matches, ['Foo.bar'])
385385

386-
# 3. Edge Cases
386+
# 3. Edge cases
387387
def test_updating_namespace_complete(self):
388388
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
389389
self.set_input_line("foo")
@@ -400,6 +400,19 @@ def test_file_should_not_appear_in_complete(self):
400400
self.assertTrue(hasattr(self.repl.matches_iter, 'matches'))
401401
self.assertNotIn('__file__', self.repl.matches_iter.matches)
402402

403+
# 4. Parameter names
404+
def test_paremeter_name_completion(self):
405+
self.repl = FakeRepl({'autocomplete_mode': autocomplete.SIMPLE})
406+
self.set_input_line("foo(ab")
407+
408+
code = "def foo(abc=1, abd=2, xyz=3):\n\tpass\n"
409+
for line in code.split("\n"):
410+
self.repl.push(line)
411+
412+
self.assertTrue(self.repl.complete())
413+
self.assertTrue(hasattr(self.repl.matches_iter, 'matches'))
414+
self.assertEqual(self.repl.matches_iter.matches, ['abc=', 'abd=', 'abs('])
415+
403416

404417
class TestCliRepl(unittest.TestCase):
405418

0 commit comments

Comments
 (0)