Skip to content

Commit

Permalink
Fix when yield from was made of an AnyType (python#868, the generic e…
Browse files Browse the repository at this point in the history
…xample

that @nierob reported in python#836)

Now don't crash in:

```
import asyncio

@asyncio.coroutine
def example_coro():
    q = asyncio.Queue()
    msg = yield from q.get()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(example_coro())
```

But that example is because don't infer asyncio.Queue type properly as
is appointed in python#836, so q is AnyType

and

```
import asyncio
import typing

@asyncio.coroutine
def foo(a):
   b = yield from a
   return b
```
  • Loading branch information
rockneurotiko committed Sep 10, 2015
1 parent dcff596 commit 45ff97a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,9 @@ def visit_yield_from_expr(self, e: YieldFromExpr) -> Type:
# result = self.expr_checker.visit_yield_from_expr(e)
result = self.accept(e.expr)
result_instance = cast(Instance, result)
if result_instance.type.fullname() == "asyncio.futures.Future":
if isinstance(result_instance, AnyType):
result = AnyType()
elif result_instance.type.fullname() == "asyncio.futures.Future":
self.function_stack[-1].is_coroutine = True # Set the function as coroutine
result = result_instance.args[0] # Set the return type as the type inside
elif is_subtype(result, self.named_type('typing.Iterable')):
Expand Down

0 comments on commit 45ff97a

Please sign in to comment.