Skip to content

Commit 563f5cb

Browse files
committed
Filter out two underscore attributes in auto completion
This change will require you to write two underscores in order to get autocompletion of attributes starting with two underscores, as requested in bpython#528. Fixes bpython#528
1 parent bbfcb2d commit 563f5cb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

bpython/autocomplete.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ def matches(self, cursor_offset, line, **kwargs):
253253
# TODO add open paren for methods via _callable_prefix (or decide not
254254
# to) unless the first character is a _ filter out all attributes
255255
# starting with a _
256-
if not r.word.split('.')[-1].startswith('_'):
256+
if r.word.split('.')[-1].startswith('__'):
257+
pass
258+
elif r.word.split('.')[-1].startswith('_'):
259+
matches = set(match for match in matches
260+
if not match.split('.')[-1].startswith('__'))
261+
else:
257262
matches = set(match for match in matches
258263
if not match.split('.')[-1].startswith('_'))
259264
return matches

bpython/test/test_autocomplete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ def test_att_matches_found_on_old_style_instance(self):
245245
locals_={'a': OldStyleFoo()}),
246246
set(['a.method', 'a.a', 'a.b']))
247247
self.assertIn(u'a.__dict__',
248-
self.com.matches(3, 'a._', locals_={'a': OldStyleFoo()}))
248+
self.com.matches(3, 'a.__', locals_={'a': OldStyleFoo()}))
249249

250250
@skip_old_style
251251
def test_att_matches_found_on_old_style_class_object(self):
252252
self.assertIn(u'A.__dict__',
253-
self.com.matches(3, 'A._', locals_={'A': OldStyleFoo}))
253+
self.com.matches(3, 'A.__', locals_={'A': OldStyleFoo}))
254254

255255
@skip_old_style
256256
def test_issue536(self):
@@ -260,7 +260,7 @@ def __getattr__(self, attr):
260260

261261
locals_ = {'a': OldStyleWithBrokenGetAttr()}
262262
self.assertIn(u'a.__module__',
263-
self.com.matches(3, 'a._', locals_=locals_))
263+
self.com.matches(3, 'a.__', locals_=locals_))
264264

265265

266266
class TestMagicMethodCompletion(unittest.TestCase):

0 commit comments

Comments
 (0)