Skip to content

Commit 796ae49

Browse files
author
Mary Mokuolu
committed
1 parent a84c2a2 commit 796ae49

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

bpython/autocomplete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def matches(self, cursor_offset, line, locals_, **kwargs):
219219
obj = safe_eval(dexpr, locals_)
220220
except EvaluationError:
221221
return set()
222-
if obj and isinstance(obj, type({})) and obj.keys():
223-
return set("{!r}".format(k) for k in obj.keys()
222+
if isinstance(obj, dict) and obj.keys():
223+
return set("{0!r}".format(k) for k in obj.keys()
224224
if repr(k).startswith(orig))
225225
else:
226226
return set()

bpython/test/test_autocomplete.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_formatting_takes_just_last_part(self):
147147

148148
class MockNumPy(object):
149149
"""
150-
This is a mock numpy object that raises an error when it is trying to be converted to a boolean.
150+
This is a mock numpy object that raises an error when there is an atempt to convert it to a boolean.
151151
"""
152152
def __nonzero__(self):
153153
raise ValueError("The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()")
@@ -158,25 +158,20 @@ class TestDictKeyCompletion(unittest.TestCase):
158158
def test_set_of_keys_returned_when_matches_found(self):
159159
com = autocomplete.DictKeyCompletion()
160160
local={'d':{"ab":1, "cd":2},}
161-
result=com.matches(2,"d[" , local)
162-
self.assertSetEqual(result,set(["'ab'","'cd'"]))
161+
com.matches(2,"d[" , local)
162+
self.assertSetEqual(com.matches(2,"d[" , local),set(["'ab'","'cd'"]))
163163

164164
def test_empty_set_returned_when_eval_error(self):
165165
com = autocomplete.DictKeyCompletion()
166166
local={'e':{"ab":1, "cd":2},}
167-
result=com.matches(2,"d[" , local)
168-
self.assertSetEqual(result,set())
167+
self.assertSetEqual(com.matches(2,"d[" , local),set())
169168

170169
def test_empty_set_returned_when_not_dict_type(self):
171170
com = autocomplete.DictKeyCompletion()
172171
local={'l':["ab", "cd"],}
173-
result=com.matches(2,"l[" , local)
174-
self.assertSetEqual(result,set())
172+
self.assertSetEqual(com.matches(2,"l[" , local),set())
175173

176-
def test_obj_that_does_not_allow_bool_tests(self):
174+
def test_obj_that_does_not_allow_conversion_to_bool(self):
177175
com = autocomplete.DictKeyCompletion()
178176
local={'mNumPy':MockNumPy(),}
179-
try:
180-
com.matches(7,"mNumPy[" , local)
181-
except ValueError:
182-
raise AssertionError("Dict key completion raised value error.")
177+
self.assertSetEqual(com.matches(7,"mNumPy[" , local), set())

0 commit comments

Comments
 (0)