mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Fix some usage cases of comprehensions.
This commit is contained in:
@@ -529,8 +529,8 @@ class Evaluator(object):
|
||||
elif node.type == 'dictorsetmaker':
|
||||
for n in node.children[1:4]:
|
||||
# In dictionaries it can be pretty much anything.
|
||||
if node.children[1].type == 'comp_for':
|
||||
return node
|
||||
if n.type == 'comp_for':
|
||||
return n
|
||||
|
||||
def from_scope_node(scope_node, child_is_funcdef=None, is_nested=True):
|
||||
if scope_node == base_node:
|
||||
@@ -563,6 +563,8 @@ class Evaluator(object):
|
||||
else:
|
||||
return class_context
|
||||
elif scope_node.type == 'comp_for':
|
||||
if node.start_pos >= scope_node.children[-1].start_pos:
|
||||
return parent_context
|
||||
return iterable.CompForContext.from_comp_for(parent_context, scope_node)
|
||||
raise Exception("There's a scope that was not managed.")
|
||||
|
||||
|
||||
@@ -273,3 +273,28 @@ _sre
|
||||
|
||||
#< 0
|
||||
import undefined
|
||||
|
||||
# -----------------
|
||||
# comprehensions
|
||||
# -----------------
|
||||
|
||||
#< 0 (0,0), (2,12)
|
||||
x = 32
|
||||
#< 12 (-2,0), (0,12)
|
||||
[x for x in x]
|
||||
|
||||
#< 0 (0,0), (2,1), (2,12)
|
||||
x = 32
|
||||
#< 12 (-2,0), (0,1), (0,12)
|
||||
[x for b in x]
|
||||
|
||||
|
||||
#< 1 (0,1), (0,7)
|
||||
[x for x in something]
|
||||
#< 7 (0,1), (0,7)
|
||||
[x for x in something]
|
||||
|
||||
#< 1 (0,1), (0,10)
|
||||
{x:1 for x in something}
|
||||
#< 10 (0,1), (0,10)
|
||||
{x:1 for x in something}
|
||||
|
||||
@@ -17,8 +17,9 @@ tuple(a + 3 for a in [''])
|
||||
# Some variables within are not defined
|
||||
# ----------
|
||||
|
||||
abcdef = None
|
||||
#! 12 name-error
|
||||
[1 for a in NOT_DEFINFED for b in a if 1]
|
||||
[1 for a in NOT_DEFINFED for b in abcdef if 1]
|
||||
|
||||
#! 25 name-error
|
||||
[1 for a in [1] for b in NOT_DEFINED if 1]
|
||||
|
||||
Reference in New Issue
Block a user