diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 90afbec8..9ba8d219 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -41,7 +41,9 @@ def filter_after_position(names, position): names_new = [] for n in names: - if n.start_pos[0] is not None and n.start_pos < position: + # Filter positions and also allow list comprehensions and lambdas. + if n.start_pos[0] is not None and n.start_pos < position \ + or isinstance(n.get_definition(), (pr.CompFor, pr.Lambda)): names_new.append(n) return names_new @@ -54,8 +56,6 @@ def filter_definition_names(names, origin, position=None): # Just calculate the scope from the first stmt = names[0].get_definition() scope = stmt.get_parent_scope() - if isinstance(stmt, (pr.CompFor, pr.Lambda)): - return names if not (isinstance(scope, er.FunctionExecution) and isinstance(scope.base, er.LambdaWrapper)): diff --git a/test/completion/basic.py b/test/completion/basic.py index efc118f0..9dfbb131 100644 --- a/test/completion/basic.py +++ b/test/completion/basic.py @@ -135,6 +135,12 @@ a = [a for a in [1]] #? int() a[0] +y = 1.0 +# Should not leak. +[y for y in [3]] +#? float() +y + a = [a for a in (1, 2)] #? int() a[0] @@ -229,6 +235,14 @@ left, right = (i for i in #? str() left +# ----------------- +# name resolution in comprehensions. +# ----------------- + +def x(): + #? 22 + [a for a in h if hio] + if hio: pass # ----------------- # ternary operator