Skip to content

Commit ad8958f

Browse files
committed
Merge remote-tracking branch 'llllllllll/old-style-class-dict-autocomplete' (merged bpython#511)
Conflicts: bpython/autocomplete.py
2 parents 27b9493 + a82b4b5 commit ad8958f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

bpython/autocomplete.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
from bpython._py3compat import py3, try_decode
4343
from bpython.lazyre import LazyReCompile
4444

45+
if not py3:
46+
from types import InstanceType, ClassType
47+
4548

4649
# Autocomplete modes
4750
SIMPLE = 'simple'
@@ -303,6 +306,10 @@ def attr_lookup(self, obj, expr, attr):
303306
except ValueError:
304307
pass
305308

309+
if not py3 and isinstance(obj, (InstanceType, ClassType)):
310+
# Account for the __dict__ in an old-style class.
311+
words.append('__dict__')
312+
306313
matches = []
307314
n = len(attr)
308315
for word in words:

bpython/test/test_autocomplete.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,42 @@ def method(self, x):
215215
pass
216216

217217

218+
class OldStyleFoo:
219+
a = 10
220+
221+
def __init__(self):
222+
self.b = 20
223+
224+
def method(self, x):
225+
pass
226+
227+
228+
skip_old_style = unittest.skipIf(py3,
229+
'In Python 3 there are no old style classes')
230+
231+
218232
class TestAttrCompletion(unittest.TestCase):
233+
@classmethod
234+
def setUpClass(cls):
235+
cls.com = autocomplete.AttrCompletion()
219236

220237
def test_att_matches_found_on_instance(self):
221-
com = autocomplete.AttrCompletion()
222-
self.assertSetEqual(com.matches(2, 'a.', locals_={'a': Foo()}),
238+
self.assertSetEqual(self.com.matches(2, 'a.', locals_={'a': Foo()}),
223239
set(['a.method', 'a.a', 'a.b']))
224240

241+
@skip_old_style
242+
def test_att_matches_found_on_old_style_instance(self):
243+
self.assertSetEqual(self.com.matches(2, 'a.',
244+
locals_={'a': OldStyleFoo()}),
245+
set(['a.method', 'a.a', 'a.b']))
246+
self.assertIn(u'a.__dict__',
247+
self.com.matches(3, 'a._', locals_={'a': OldStyleFoo()}))
248+
249+
@skip_old_style
250+
def test_att_matches_found_on_old_style_class_object(self):
251+
self.assertIn(u'A.__dict__',
252+
self.com.matches(3, 'A._', locals_={'A': OldStyleFoo}))
253+
225254

226255
class TestMagicMethodCompletion(unittest.TestCase):
227256

0 commit comments

Comments
 (0)