Skip to content

Commit

Permalink
Avoid aborting search for yields when they are still reachable, see #683
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Jan 28, 2020
1 parent bec87f7 commit d630ed5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
22 changes: 11 additions & 11 deletions jedi/inference/value/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ def get_return_values(self, check_yields=False):
returns = funcdef.iter_return_stmts()

for r in returns:
check = flow_analysis.reachability_check(self, funcdef, r)
if check is flow_analysis.UNREACHABLE:
debug.dbg('Return unreachable: %s', r)
if check_yields:
value_set |= ValueSet.from_sets(
lazy_value.infer()
for lazy_value in self._get_yield_lazy_value(r)
)
else:
if check_yields:
value_set |= ValueSet.from_sets(
lazy_value.infer()
for lazy_value in self._get_yield_lazy_value(r)
)
check = flow_analysis.reachability_check(self, funcdef, r)
if check is flow_analysis.UNREACHABLE:
debug.dbg('Return unreachable: %s', r)
else:
try:
children = r.children
Expand All @@ -218,9 +218,9 @@ def get_return_values(self, check_yields=False):
value_set |= ValueSet([ctx])
else:
value_set |= self.infer_node(children[1])
if check is flow_analysis.REACHABLE:
debug.dbg('Return reachable: %s', r)
break
if check is flow_analysis.REACHABLE:
debug.dbg('Return reachable: %s', r)
break
return value_set

def _get_yield_lazy_value(self, yield_expr):
Expand Down
22 changes: 22 additions & 0 deletions test/completion/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ def __iter__(self):
#? float()
next(g)

x, y = Get()
#? int() str()
x
#? int() str()
x

class Iter:
def __iter__(self):
yield ""
i = 0
while True:
v = 1
yield v
i += 1
a, b, c = Iter()
#? str() int()
a
#? str() int()
b
#? str() int()
c


# -----------------
# __next__
Expand Down

0 comments on commit d630ed5

Please sign in to comment.