Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when yield from was made of an AnyType #873

Closed
wants to merge 1 commit into from

Conversation

rockneurotiko
Copy link
Contributor

As reported in #868 and the generic example that @nierob reported in #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 #836, and q is AnyType (instead of asyncio.Queue)

and

import asyncio
import typing

@asyncio.coroutine
def foo(a):
   b = yield from a
   return b

…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
```
@gladhorn
Copy link

I haven't looked into the issue much, but this commit fixes several crashes I was experiencing.

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 7, 2015

Thanks for the PR! It would be great if you could add a test case for this as well.

Also, this doesn't address the root problem, which is an unsafe cast in visit_yield_from_expr:

    def visit_yield_from_expr(self, e: YieldFromExpr) -> Type:
        result = self.accept(e.expr)
        result_instance = cast(Instance, result)   # result could be any type -- cast is unsafe!
        ...

This can still fail if the result type is something other than Any or an instance type.

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 17, 2015

Closing as #944 contained fixes to the issues.

@JukkaL JukkaL closed this Oct 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants