1
0
forked from VimPlug/jedi

fix a set comprehension issue

This commit is contained in:
Tzerjen Wei
2015-07-29 00:08:21 +08:00
parent 7b50bb00b9
commit 4cc6cb3ac4
2 changed files with 32 additions and 1 deletions

View File

@@ -242,7 +242,7 @@ class Evaluator(object):
except (IndexError, AttributeError): except (IndexError, AttributeError):
pass pass
else: 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.Comprehension.from_atom(self, atom)]
return [iterable.Array(self, atom)] return [iterable.Array(self, atom)]

View File

@@ -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