mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Replace function call with set literal
This commit is contained in:
@@ -243,7 +243,7 @@ def _execute_array_values(evaluator, array):
|
||||
for typ in lazy_context.infer()
|
||||
)
|
||||
values.append(LazyKnownContexts(objects))
|
||||
return set([FakeSequence(evaluator, array.array_type, values)])
|
||||
return {FakeSequence(evaluator, array.array_type, values)}
|
||||
else:
|
||||
return array.execute_evaluated()
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class AbstractNameDefinition(object):
|
||||
def goto(self):
|
||||
# Typically names are already definitions and therefore a goto on that
|
||||
# name will always result on itself.
|
||||
return set([self])
|
||||
return {self}
|
||||
|
||||
def get_root_context(self):
|
||||
return self.parent_context.get_root_context()
|
||||
|
||||
@@ -286,10 +286,10 @@ def eval_or_test(context, or_test):
|
||||
# handle lazy evaluation of and/or here.
|
||||
if operator in ('and', 'or'):
|
||||
left_bools = set(left.py__bool__() for left in types)
|
||||
if left_bools == set([True]):
|
||||
if left_bools == {True}:
|
||||
if operator == 'and':
|
||||
types = context.eval_node(right)
|
||||
elif left_bools == set([False]):
|
||||
elif left_bools == {False}:
|
||||
if operator != 'and':
|
||||
types = context.eval_node(right)
|
||||
# Otherwise continue, because of uncertainty.
|
||||
|
||||
@@ -4,11 +4,10 @@ from inspect import cleandoc
|
||||
from jedi._compatibility import literal_eval, is_py3
|
||||
from parso.python import tree
|
||||
|
||||
_EXECUTE_NODES = set([
|
||||
'funcdef', 'classdef', 'import_from', 'import_name', 'test', 'or_test',
|
||||
'and_test', 'not_test', 'comparison', 'expr', 'xor_expr', 'and_expr',
|
||||
'shift_expr', 'arith_expr', 'atom_expr', 'term', 'factor', 'power', 'atom'
|
||||
])
|
||||
_EXECUTE_NODES = {'funcdef', 'classdef', 'import_from', 'import_name', 'test',
|
||||
'or_test', 'and_test', 'not_test', 'comparison', 'expr',
|
||||
'xor_expr', 'and_expr', 'shift_expr', 'arith_expr',
|
||||
'atom_expr', 'term', 'factor', 'power', 'atom'}
|
||||
|
||||
_FLOW_KEYWORDS = (
|
||||
'try', 'except', 'finally', 'else', 'if', 'elif', 'with', 'for', 'while'
|
||||
|
||||
@@ -254,7 +254,7 @@ C().list_arr(1.0)[0]
|
||||
# array recursions
|
||||
# -----------------
|
||||
|
||||
a = set([1.0])
|
||||
a = {1.0}
|
||||
a.update(a)
|
||||
a.update([1])
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ def test_completion_on_complex_literals():
|
||||
# No dot no completion - I thought, but 4j is actually a literall after
|
||||
# which a keyword like or is allowed. Good times, haha!
|
||||
assert (set([c.name for c in api.Script('4j').completions()]) ==
|
||||
set(['if', 'and', 'in', 'is', 'not', 'or']))
|
||||
{'if', 'and', 'in', 'is', 'not', 'or'})
|
||||
|
||||
|
||||
def test_goto_assignments_on_non_name():
|
||||
@@ -152,7 +152,7 @@ def test_goto_definition_not_multiple():
|
||||
|
||||
def test_usage_description():
|
||||
descs = [u.description for u in api.Script("foo = ''; foo").usages()]
|
||||
assert set(descs) == set(["foo = ''", 'foo'])
|
||||
assert set(descs) == {"foo = ''", 'foo'}
|
||||
|
||||
|
||||
def test_get_line_code():
|
||||
|
||||
@@ -34,7 +34,8 @@ def test_follow_import_incomplete():
|
||||
|
||||
# incomplete `from * import` part
|
||||
datetime = check_follow_definition_types("from datetime import datetim")
|
||||
assert set(datetime) == set(['class', 'instance']) # py33: builtin and pure py version
|
||||
assert set(datetime) == {'class',
|
||||
'instance'} # py33: builtin and pure py version
|
||||
|
||||
# os.path check
|
||||
ospath = check_follow_definition_types("from os.path import abspat")
|
||||
|
||||
@@ -71,22 +71,22 @@ def test_basedefinition_type_import():
|
||||
return set([t.type for t in Script(source, **kwargs).completions()])
|
||||
|
||||
# import one level
|
||||
assert get_types('import t') == set(['module'])
|
||||
assert get_types('import ') == set(['module'])
|
||||
assert get_types('import datetime; datetime') == set(['module'])
|
||||
assert get_types('import t') == {'module'}
|
||||
assert get_types('import ') == {'module'}
|
||||
assert get_types('import datetime; datetime') == {'module'}
|
||||
|
||||
# from
|
||||
assert get_types('from datetime import timedelta') == set(['class'])
|
||||
assert get_types('from datetime import timedelta; timedelta') == set(['class'])
|
||||
assert get_types('from json import tool') == set(['module'])
|
||||
assert get_types('from json import tool; tool') == set(['module'])
|
||||
assert get_types('from datetime import timedelta') == {'class'}
|
||||
assert get_types('from datetime import timedelta; timedelta') == {'class'}
|
||||
assert get_types('from json import tool') == {'module'}
|
||||
assert get_types('from json import tool; tool') == {'module'}
|
||||
|
||||
# import two levels
|
||||
assert get_types('import json.tool; json') == set(['module'])
|
||||
assert get_types('import json.tool; json.tool') == set(['module'])
|
||||
assert get_types('import json.tool; json.tool.main') == set(['function'])
|
||||
assert get_types('import json.tool') == set(['module'])
|
||||
assert get_types('import json.tool', column=9) == set(['module'])
|
||||
assert get_types('import json.tool; json') == {'module'}
|
||||
assert get_types('import json.tool; json.tool') == {'module'}
|
||||
assert get_types('import json.tool; json.tool.main') == {'function'}
|
||||
assert get_types('import json.tool') == {'module'}
|
||||
assert get_types('import json.tool', column=9) == {'module'}
|
||||
|
||||
|
||||
def test_function_call_signature_in_doc():
|
||||
|
||||
@@ -261,7 +261,7 @@ def test_completion_param_annotations():
|
||||
a, b, c = c.params
|
||||
assert a._goto_definitions() == []
|
||||
assert [d.name for d in b._goto_definitions()] == ['str']
|
||||
assert set([d.name for d in c._goto_definitions()]) == set(['int', 'float'])
|
||||
assert set([d.name for d in c._goto_definitions()]) == {'int', 'float'}
|
||||
|
||||
|
||||
def test_more_complex_instances():
|
||||
|
||||
@@ -156,7 +156,7 @@ def test_complete_on_empty_import():
|
||||
# relative import
|
||||
assert 10 < len(Script("from . import classes", 1, 6, 'whatever.py').completions()) < 30
|
||||
|
||||
wanted = set(['ImportError', 'import', 'ImportWarning'])
|
||||
wanted = {'ImportError', 'import', 'ImportWarning'}
|
||||
assert set([c.name for c in Script("import").completions()]) == wanted
|
||||
assert len(Script("import import", path='').completions()) > 0
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_namedtuple_list():
|
||||
garfield.l""")
|
||||
result = Script(source).completions()
|
||||
completions = set(r.name for r in result)
|
||||
assert completions == set(['legs', 'length', 'large'])
|
||||
assert completions == {'legs', 'length', 'large'}
|
||||
|
||||
|
||||
def test_namedtuple_content():
|
||||
|
||||
@@ -14,9 +14,9 @@ def test_paths_from_assignment():
|
||||
expr_stmt = script._get_module_node().children[0]
|
||||
return set(sys_path._paths_from_assignment(script._get_module(), expr_stmt))
|
||||
|
||||
assert paths('sys.path[0:0] = ["a"]') == set(['/foo/a'])
|
||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == set(['/foo/b', '/foo/c'])
|
||||
assert paths('sys.path = a = ["a"]') == set(['/foo/a'])
|
||||
assert paths('sys.path[0:0] = ["a"]') == {'/foo/a'}
|
||||
assert paths('sys.path = ["b", 1, x + 3, y, "c"]') == {'/foo/b', '/foo/c'}
|
||||
assert paths('sys.path = a = ["a"]') == {'/foo/a'}
|
||||
|
||||
# Fail for complicated examples.
|
||||
assert paths('sys.path, other = ["a"], 2') == set()
|
||||
|
||||
@@ -68,7 +68,7 @@ class TestSetupReadline(unittest.TestCase):
|
||||
|
||||
def test_import(self):
|
||||
s = 'from os.path import a'
|
||||
assert set(self.completions(s)) == set([s + 'ltsep', s + 'bspath'])
|
||||
assert set(self.completions(s)) == {s + 'ltsep', s + 'bspath'}
|
||||
assert self.completions('import keyword') == ['import keyword']
|
||||
|
||||
import os
|
||||
|
||||
Reference in New Issue
Block a user