Skip to content

Commit eaef6d0

Browse files
committed
Use set literals
1 parent d3248ca commit eaef6d0

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

bpython/autocomplete.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,16 @@ def matches(self, cursor_offset, line, **kwargs):
297297
i -= 1
298298
break
299299
methodtext = r.word[-i:]
300-
matches = set(
300+
matches = {
301301
"".join([r.word[:-i], m])
302302
for m in self.attr_matches(methodtext, locals_)
303-
)
303+
}
304304

305-
return set(
305+
return {
306306
m
307307
for m in matches
308308
if few_enough_underscores(r.word.split(".")[-1], m.split(".")[-1])
309-
)
309+
}
310310

311311
def locate(self, current_offset, line):
312312
return lineparts.current_dotted_attribute(current_offset, line)
@@ -376,11 +376,11 @@ def matches(self, cursor_offset, line, **kwargs):
376376
except EvaluationError:
377377
return None
378378
if isinstance(obj, dict) and obj.keys():
379-
matches = set(
379+
matches = {
380380
"{0!r}]".format(k)
381381
for k in obj.keys()
382382
if repr(k).startswith(r.word)
383-
)
383+
}
384384
return matches if matches else None
385385
else:
386386
return None
@@ -403,7 +403,7 @@ def matches(self, cursor_offset, line, **kwargs):
403403
return None
404404
if "class" not in current_block:
405405
return None
406-
return set(name for name in MAGIC_METHODS if name.startswith(r.word))
406+
return {name for name in MAGIC_METHODS if name.startswith(r.word)}
407407

408408
def locate(self, current_offset, line):
409409
return lineparts.current_method_definition_name(current_offset, line)
@@ -456,11 +456,11 @@ def matches(self, cursor_offset, line, **kwargs):
456456
if r is None:
457457
return None
458458
if argspec:
459-
matches = set(
459+
matches = {
460460
name + "="
461461
for name in argspec[1][0]
462462
if isinstance(name, str) and name.startswith(r.word)
463-
)
463+
}
464464
matches.update(
465465
name + "="
466466
for name in argspec[1][4]
@@ -494,7 +494,7 @@ def matches(self, cursor_offset, line, **kwargs):
494494

495495
# strips leading dot
496496
matches = [m[1:] for m in self.attr_lookup(obj, "", attr.word)]
497-
return set(m for m in matches if few_enough_underscores(attr.word, m))
497+
return {m for m in matches if few_enough_underscores(attr.word, m)}
498498

499499

500500
try:
@@ -547,7 +547,7 @@ def matches(self, cursor_offset, line, **kwargs):
547547
return None
548548
else:
549549
# case-sensitive matches only
550-
return set(m for m in matches if m.startswith(first_letter))
550+
return {m for m in matches if m.startswith(first_letter)}
551551

552552
def locate(self, cursor_offset, line):
553553
start = self._orig_start

bpython/importcompletion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def module_matches(cw, prefix=""):
5656
if (name.startswith(full) and name.find(".", len(full)) == -1)
5757
)
5858
if prefix:
59-
return set(match[len(prefix) + 1 :] for match in matches)
59+
return {match[len(prefix) + 1 :] for match in matches}
6060
else:
6161
return set(matches)
6262

bpython/test/test_autocomplete.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_two_completers_get_both(self):
110110
a = self.completer(["a"])
111111
b = self.completer(["b"])
112112
cumulative = autocomplete.CumulativeCompleter([a, b])
113-
self.assertEqual(cumulative.matches(3, "abc"), set(["a", "b"]))
113+
self.assertEqual(cumulative.matches(3, "abc"), {"a", "b"})
114114

115115

116116
class TestFilenameCompletion(unittest.TestCase):
@@ -187,7 +187,7 @@ def test_set_of_keys_returned_when_matches_found(self):
187187
com = autocomplete.DictKeyCompletion()
188188
local = {"d": {"ab": 1, "cd": 2}}
189189
self.assertSetEqual(
190-
com.matches(2, "d[", locals_=local), set(["'ab']", "'cd']"])
190+
com.matches(2, "d[", locals_=local), {"'ab']", "'cd']"}
191191
)
192192

193193
def test_none_returned_when_eval_error(self):
@@ -254,27 +254,27 @@ def setUpClass(cls):
254254
def test_att_matches_found_on_instance(self):
255255
self.assertSetEqual(
256256
self.com.matches(2, "a.", locals_={"a": Foo()}),
257-
set(["a.method", "a.a", "a.b"]),
257+
{"a.method", "a.a", "a.b"},
258258
)
259259

260260
def test_descriptor_attributes_not_run(self):
261261
com = autocomplete.AttrCompletion()
262262
self.assertSetEqual(
263263
com.matches(2, "a.", locals_={"a": Properties()}),
264-
set(["a.b", "a.a", "a.method", "a.asserts_when_called"]),
264+
{"a.b", "a.a", "a.method", "a.asserts_when_called"},
265265
)
266266

267267
def test_custom_get_attribute_not_invoked(self):
268268
com = autocomplete.AttrCompletion()
269269
self.assertSetEqual(
270270
com.matches(2, "a.", locals_={"a": OverriddenGetattribute()}),
271-
set(["a.b", "a.a", "a.method"]),
271+
{"a.b", "a.a", "a.method"},
272272
)
273273

274274
def test_slots_not_crash(self):
275275
com = autocomplete.AttrCompletion()
276276
self.assertSetEqual(
277-
com.matches(2, "A.", locals_={"A": Slots}), set(["A.b", "A.a"]),
277+
com.matches(2, "A.", locals_={"A": Slots}), {"A.b", "A.a"},
278278
)
279279

280280

@@ -286,7 +286,7 @@ def setUpClass(cls):
286286
def test_att_matches_found_on_instance(self):
287287
self.assertSetEqual(
288288
self.com.matches(5, "a[0].", locals_={"a": [Foo()]}),
289-
set(["method", "a", "b"]),
289+
{"method", "a", "b"},
290290
)
291291

292292
def test_other_getitem_methods_not_called(self):
@@ -299,7 +299,7 @@ def __getitem__(inner_self, i):
299299
def test_tuples_complete(self):
300300
self.assertSetEqual(
301301
self.com.matches(5, "a[0].", locals_={"a": (Foo(),)}),
302-
set(["method", "a", "b"]),
302+
{"method", "a", "b"},
303303
)
304304

305305
@unittest.skip("TODO, subclasses do not complete yet")
@@ -309,7 +309,7 @@ class ListSubclass(list):
309309

310310
self.assertSetEqual(
311311
self.com.matches(5, "a[0].", locals_={"a": ListSubclass([Foo()])}),
312-
set(["method", "a", "b"]),
312+
{"method", "a", "b"},
313313
)
314314

315315
def test_getitem_not_called_in_list_subclasses_overriding_getitem(self):
@@ -322,13 +322,13 @@ def __getitem__(inner_self, i):
322322
def test_literals_complete(self):
323323
self.assertSetEqual(
324324
self.com.matches(10, "[a][0][0].", locals_={"a": (Foo(),)}),
325-
set(["method", "a", "b"]),
325+
{"method", "a", "b"},
326326
)
327327

328328
def test_dictionaries_complete(self):
329329
self.assertSetEqual(
330330
self.com.matches(7, 'a["b"].', locals_={"a": {"b": Foo()}}),
331-
set(["method", "a", "b"]),
331+
{"method", "a", "b"},
332332
)
333333

334334

@@ -391,7 +391,7 @@ def test_completions_starting_with_different_cases(self):
391391
["adsf"],
392392
[Comp("Abc", "bc"), Comp("ade", "de")],
393393
)
394-
self.assertSetEqual(matches, set(["ade"]))
394+
self.assertSetEqual(matches, {"ade"})
395395

396396
def test_issue_544(self):
397397
com = autocomplete.MultilineJediCompletion()
@@ -410,12 +410,12 @@ def function():
410410

411411
self.assertEqual(
412412
self.com.matches(8, "function", locals_={"function": function}),
413-
set(("function(",)),
413+
{"function("},
414414
)
415415

416416
def test_completions_are_unicode(self):
417417
for m in self.com.matches(1, "a", locals_={"abc": 10}):
418-
self.assertIsInstance(m, type(u""))
418+
self.assertIsInstance(m, type(""))
419419

420420
def test_mock_kwlist(self):
421421
with mock.patch.object(keyword, "kwlist", new=["abcd"]):
@@ -435,11 +435,11 @@ def func(apple, apricot, banana, carrot):
435435
argspec = ["func", argspec, False]
436436
com = autocomplete.ParameterNameCompletion()
437437
self.assertSetEqual(
438-
com.matches(1, "a", argspec=argspec), set(["apple=", "apricot="])
438+
com.matches(1, "a", argspec=argspec), {"apple=", "apricot="}
439439
)
440440
self.assertSetEqual(
441-
com.matches(2, "ba", argspec=argspec), set(["banana="])
441+
com.matches(2, "ba", argspec=argspec), {"banana="}
442442
)
443443
self.assertSetEqual(
444-
com.matches(3, "car", argspec=argspec), set(["carrot="])
444+
com.matches(3, "car", argspec=argspec), {"carrot="}
445445
)

bpython/test/test_importcompletion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def tearDown(self):
1818

1919
def test_simple_completion(self):
2020
self.assertSetEqual(
21-
importcompletion.complete(10, "import zza"), set(["zzabc", "zzabd"])
21+
importcompletion.complete(10, "import zza"), {"zzabc", "zzabd"}
2222
)
2323

2424
def test_package_completion(self):
2525
self.assertSetEqual(
2626
importcompletion.complete(13, "import zzabc."),
27-
set(["zzabc.e", "zzabc.f"]),
27+
{"zzabc.e", "zzabc.f"},
2828
)
2929

3030

@@ -43,15 +43,15 @@ def tearDownClass(cls):
4343

4444
def test_from_attribute(self):
4545
self.assertSetEqual(
46-
importcompletion.complete(19, "from sys import arg"), set(["argv"])
46+
importcompletion.complete(19, "from sys import arg"), {"argv"}
4747
)
4848

4949
def test_from_attr_module(self):
5050
self.assertSetEqual(
51-
importcompletion.complete(9, "from os.p"), set(["os.path"])
51+
importcompletion.complete(9, "from os.p"), {"os.path"}
5252
)
5353

5454
def test_from_package(self):
5555
self.assertSetEqual(
56-
importcompletion.complete(17, "from xml import d"), set(["dom"])
56+
importcompletion.complete(17, "from xml import d"), {"dom"}
5757
)

0 commit comments

Comments
 (0)