From cc623218e5927f2004bc66381521f26d6d9d047b Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 4 Jan 2018 16:37:50 +0200 Subject: [PATCH] Replace function call with set literal --- jedi/evaluate/docstrings.py | 2 +- jedi/evaluate/filters.py | 2 +- jedi/evaluate/syntax_tree.py | 4 ++-- jedi/parser_utils.py | 9 ++++--- test/completion/dynamic_arrays.py | 2 +- test/test_api/test_api.py | 4 ++-- .../test_api_classes_follow_definition.py | 3 ++- test/test_api/test_classes.py | 24 +++++++++---------- test/test_api/test_interpreter.py | 2 +- test/test_evaluate/test_imports.py | 2 +- test/test_evaluate/test_stdlib.py | 2 +- test/test_evaluate/test_sys_path.py | 6 ++--- test/test_utils.py | 2 +- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index 4bbb0a06..ebb71b11 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -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() diff --git a/jedi/evaluate/filters.py b/jedi/evaluate/filters.py index 35dff9da..1b4754eb 100644 --- a/jedi/evaluate/filters.py +++ b/jedi/evaluate/filters.py @@ -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() diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 1d847a49..123617da 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -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. diff --git a/jedi/parser_utils.py b/jedi/parser_utils.py index 59c6408e..69decc9c 100644 --- a/jedi/parser_utils.py +++ b/jedi/parser_utils.py @@ -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' diff --git a/test/completion/dynamic_arrays.py b/test/completion/dynamic_arrays.py index e20dde86..5097c8b5 100644 --- a/test/completion/dynamic_arrays.py +++ b/test/completion/dynamic_arrays.py @@ -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]) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index a8064d7c..c456c7cb 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -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(): diff --git a/test/test_api/test_api_classes_follow_definition.py b/test/test_api/test_api_classes_follow_definition.py index ffc0cb64..9ecbe0d1 100644 --- a/test/test_api/test_api_classes_follow_definition.py +++ b/test/test_api/test_api_classes_follow_definition.py @@ -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") diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index cc01c2a3..1e0d952d 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -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(): diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 8e91e566..89a0bb75 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -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(): diff --git a/test/test_evaluate/test_imports.py b/test/test_evaluate/test_imports.py index 307b811c..738c1cdc 100644 --- a/test/test_evaluate/test_imports.py +++ b/test/test_evaluate/test_imports.py @@ -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 diff --git a/test/test_evaluate/test_stdlib.py b/test/test_evaluate/test_stdlib.py index 6b55224d..3ba3f79f 100644 --- a/test/test_evaluate/test_stdlib.py +++ b/test/test_evaluate/test_stdlib.py @@ -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(): diff --git a/test/test_evaluate/test_sys_path.py b/test/test_evaluate/test_sys_path.py index 7bedfa17..e825912d 100644 --- a/test/test_evaluate/test_sys_path.py +++ b/test/test_evaluate/test_sys_path.py @@ -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() diff --git a/test/test_utils.py b/test/test_utils.py index 2eb6e8ca..367decf4 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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