Skip to content

Fix when yield from was made of an AnyType - #873

Closed
rockneurotiko wants to merge 1 commit into
python:masterfrom
rockneurotiko:master
Closed

rockneurotiko wants to merge 1 commit into
python:masterfrom
rockneurotiko:master

Conversation

@rockneurotiko

Copy link
Copy Markdown
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
Copy Markdown

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

@JukkaL

JukkaL commented Oct 7, 2015

Copy link
Copy Markdown
Collaborator

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

JukkaL commented Oct 17, 2015

Copy link
Copy Markdown
Collaborator

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