From 4cc6cb3ac44a526f43561961e7d6ad7ddbbf7da9 Mon Sep 17 00:00:00 2001 From: Tzerjen Wei Date: Wed, 29 Jul 2015 00:08:21 +0800 Subject: [PATCH 1/5] fix a set comprehension issue --- jedi/evaluate/__init__.py | 2 +- test/test_evaluate/test_iterable.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/test_evaluate/test_iterable.py diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index a959d05f..c8dca140 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -242,7 +242,7 @@ class Evaluator(object): except (IndexError, AttributeError): pass else: - if isinstance(comp_for, tree.CompFor): + if isinstance(comp_for, tree.CompFor) and c[0] != '{': return [iterable.Comprehension.from_atom(self, atom)] return [iterable.Array(self, atom)] diff --git a/test/test_evaluate/test_iterable.py b/test/test_evaluate/test_iterable.py new file mode 100644 index 00000000..a8b29f6a --- /dev/null +++ b/test/test_evaluate/test_iterable.py @@ -0,0 +1,31 @@ +from textwrap import dedent + +from jedi import names + + +def get_scope_and_evaluator(source): + d = names(dedent(source))[0] + return d.parent()._definition, d._evaluator + +def find_types(s): + scope, evaluator = get_scope_and_evaluator(s) + return evaluator.find_types(scope, s[0]) + + + +def test_comprehensions(): + """ + test list/set/generator/dict comprehension syntax + """ + + s = "a = [i for i in range(10)]" + assert len(find_types(s)) == 1 + + s = "a = [i for i in range(10)]" + assert len(find_types(s)) == 1 + + s = "a = {i:i for i in range(10)}" + assert len(find_types(s)) == 1 + + s = "a = {i for i in range(10)}" + assert len(find_types(s)) == 1 From fdcf7183172cff01e10321c83ea460fa8f006415 Mon Sep 17 00:00:00 2001 From: Tzerjen Wei Date: Sun, 9 Aug 2015 14:11:42 +0800 Subject: [PATCH 2/5] move set comprehension tests to comletion/comprehensions.py --- test/completion/comprehensions.py | 7 +++++++ test/test_evaluate/test_iterable.py | 31 ----------------------------- 2 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 test/test_evaluate/test_iterable.py diff --git a/test/completion/comprehensions.py b/test/completion/comprehensions.py index 98a15bcb..a8aaa0e9 100644 --- a/test/completion/comprehensions.py +++ b/test/completion/comprehensions.py @@ -50,6 +50,13 @@ left ##? str() {a-1:b for a,b in {1:'a', 3:1.0}.items()}[0] +# with a set literal +#? int() +[a for a in {1, 2, 3}][0] + +##? int() +{a for a in range(10)}[0] + # list comprehensions should also work in combination with functions def listen(arg): for x in arg: diff --git a/test/test_evaluate/test_iterable.py b/test/test_evaluate/test_iterable.py deleted file mode 100644 index a8b29f6a..00000000 --- a/test/test_evaluate/test_iterable.py +++ /dev/null @@ -1,31 +0,0 @@ -from textwrap import dedent - -from jedi import names - - -def get_scope_and_evaluator(source): - d = names(dedent(source))[0] - return d.parent()._definition, d._evaluator - -def find_types(s): - scope, evaluator = get_scope_and_evaluator(s) - return evaluator.find_types(scope, s[0]) - - - -def test_comprehensions(): - """ - test list/set/generator/dict comprehension syntax - """ - - s = "a = [i for i in range(10)]" - assert len(find_types(s)) == 1 - - s = "a = [i for i in range(10)]" - assert len(find_types(s)) == 1 - - s = "a = {i:i for i in range(10)}" - assert len(find_types(s)) == 1 - - s = "a = {i for i in range(10)}" - assert len(find_types(s)) == 1 From 666cbbf123d8364a603249e7a400b566a6ced0bb Mon Sep 17 00:00:00 2001 From: Tzerjen Wei Date: Sun, 9 Aug 2015 17:58:38 +0800 Subject: [PATCH 3/5] update the test of set comprehension literal --- test/completion/comprehensions.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/completion/comprehensions.py b/test/completion/comprehensions.py index a8aaa0e9..8ba1fbce 100644 --- a/test/completion/comprehensions.py +++ b/test/completion/comprehensions.py @@ -54,8 +54,18 @@ left #? int() [a for a in {1, 2, 3}][0] +#? set() +{a for a in range(10)} + ##? int() -{a for a in range(10)}[0] +[x for x in {a for a in range(10)}][0] + +##? int() +{a for a in range(10)}.pop() + +##? int() +iter({a for a in range(10)}).next() + # list comprehensions should also work in combination with functions def listen(arg): From b9902b22d6b7eb9dcc15fb533d06e358f690b696 Mon Sep 17 00:00:00 2001 From: Jonas Haag Date: Tue, 18 Aug 2015 11:44:01 +0200 Subject: [PATCH 4/5] Fix docstring --- jedi/api/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 31300974..18ca0fc7 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -62,8 +62,8 @@ class Script(object): :type source: str :param line: The line to perform actions on (starting with 1). :type line: int - :param col: The column of the cursor (starting with 0). - :type col: int + :param column: The column of the cursor (starting with 0). + :type column: int :param path: The path of the file in the file system, or ``''`` if it hasn't been saved yet. :type path: str or None From c2f8e1846e175e931ceec43c2c35cc2d61325a35 Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Wed, 26 Aug 2015 21:58:25 -0400 Subject: [PATCH 5/5] Fix #603 - Fix broken 'Tips for how to use jedi efficiently' link in README.md --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 774a4d85..f465f6b8 100644 --- a/README.rst +++ b/README.rst @@ -96,7 +96,7 @@ You can run Jedi on cPython 2.6, 2.7, 3.2, 3.3 or 3.4, but it should also understand/parse code older than those versions. Tips on how to use Jedi efficiently can be found `here -`_. +`_. API ---