Skip to content

Commit ce0bd0a

Browse files
Remove ArrayItemMembersCompletion
functionality taken over by more general ExpressionAttributeCompletion
1 parent 51ecedb commit ce0bd0a

File tree

2 files changed

+7
-66
lines changed

2 files changed

+7
-66
lines changed

bpython/autocomplete.py

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -340,63 +340,6 @@ def list_attributes(self, obj):
340340
return dir(obj)
341341

342342

343-
class ArrayItemMembersCompletion(BaseCompletionType):
344-
345-
def __init__(self, shown_before_tab=True, mode=SIMPLE):
346-
self._shown_before_tab = shown_before_tab
347-
self.completer = AttrCompletion(mode=mode)
348-
349-
def matches(self, cursor_offset, line, **kwargs):
350-
if 'locals_' not in kwargs:
351-
return None
352-
locals_ = kwargs['locals_']
353-
354-
full = self.locate(cursor_offset, line)
355-
if full is None:
356-
return None
357-
358-
arr = lineparts.current_indexed_member_access_identifier(
359-
cursor_offset, line)
360-
index = lineparts.current_indexed_member_access_identifier_with_index(
361-
cursor_offset, line)
362-
member = lineparts.current_indexed_member_access_member(
363-
cursor_offset, line)
364-
365-
try:
366-
obj = safe_eval(arr.word, locals_)
367-
except EvaluationError:
368-
return None
369-
if type(obj) not in (list, tuple) + string_types:
370-
# then is may be unsafe to do attribute lookup on it
371-
return None
372-
373-
try:
374-
locals_['temp_val_from_array'] = safe_eval(index.word, locals_)
375-
except (EvaluationError, IndexError):
376-
return None
377-
378-
temp_line = line.replace(index.word, 'temp_val_from_array.')
379-
380-
matches = self.completer.matches(len(temp_line), temp_line, **kwargs)
381-
if matches is None:
382-
return None
383-
384-
matches_with_correct_name = \
385-
set(match.replace('temp_val_from_array.', index.word+'.')
386-
for match in matches if match[20:].startswith(member.word))
387-
388-
del locals_['temp_val_from_array']
389-
390-
return matches_with_correct_name
391-
392-
def locate(self, current_offset, line):
393-
a = lineparts.current_indexed_member_access(current_offset, line)
394-
return a
395-
396-
def format(self, match):
397-
return after_last_dot(match)
398-
399-
400343
class DictKeyCompletion(BaseCompletionType):
401344

402345
def matches(self, cursor_offset, line, **kwargs):
@@ -526,8 +469,7 @@ def locate(self, current_offset, line):
526469

527470

528471
class ExpressionAttributeCompletion(AttrCompletion):
529-
# could replace ArrayItemMember completion and attr completion
530-
# as a more general case
472+
# could replace attr completion as a more general case with some work
531473
def locate(self, current_offset, line):
532474
return lineparts.current_expression_attribute(current_offset, line)
533475

@@ -676,7 +618,6 @@ def get_default_completer(mode=SIMPLE):
676618
mode=mode),
677619
AttrCompletion(mode=mode),
678620
ExpressionAttributeCompletion(mode=mode),
679-
ArrayItemMembersCompletion(mode=mode),
680621
)
681622

682623

bpython/test/test_autocomplete.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,20 @@ def __getattr__(self, attr):
268268
self.com.matches(4, 'a.__', locals_=locals_))
269269

270270

271-
class TestArrayItemCompletion(unittest.TestCase):
271+
class TestExpressionAttributeCompletion(unittest.TestCase):
272272
@classmethod
273273
def setUpClass(cls):
274-
cls.com = autocomplete.ArrayItemMembersCompletion()
274+
cls.com = autocomplete.ExpressionAttributeCompletion()
275275

276276
def test_att_matches_found_on_instance(self):
277277
self.assertSetEqual(self.com.matches(5, 'a[0].', locals_={'a': [Foo()]}),
278-
set(['a[0].method', 'a[0].a', 'a[0].b']))
278+
set(['method', 'a', 'b']))
279279

280280
@skip_old_style
281281
def test_att_matches_found_on_old_style_instance(self):
282282
self.assertSetEqual(self.com.matches(5, 'a[0].',
283283
locals_={'a': [OldStyleFoo()]}),
284-
set(['a[0].method', 'a[0].a', 'a[0].b']))
284+
set(['method', 'a', 'b']))
285285

286286
def test_other_getitem_methods_not_called(self):
287287
class FakeList(object):
@@ -293,14 +293,14 @@ def __getitem__(inner_self, i):
293293
def test_tuples_complete(self):
294294
self.assertSetEqual(self.com.matches(5, 'a[0].',
295295
locals_={'a': (Foo(),)}),
296-
set(['a[0].method', 'a[0].a', 'a[0].b']))
296+
set(['method', 'a', 'b']))
297297

298298
@unittest.skip('TODO, subclasses do not complete yet')
299299
def test_list_subclasses_complete(self):
300300
class ListSubclass(list): pass
301301
self.assertSetEqual(self.com.matches(5, 'a[0].',
302302
locals_={'a': ListSubclass([Foo()])}),
303-
set(['a[0].method', 'a[0].a', 'a[0].b']))
303+
set(['method', 'a', 'b']))
304304

305305
def test_getitem_not_called_in_list_subclasses_overriding_getitem(self):
306306
class FakeList(list):

0 commit comments

Comments
 (0)