-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Full yield support, including yield expressions #498
Labels
Comments
Also, you can do a return inside a Iterator, and get in with the yield from expression. This works: from typing import List, Iterator, Any
trace = [] # type: List[Any]
def inner() -> Iterator[int]:
try:
yield 1
except ValueError:
trace.append("inner caught ValueError")
return 2
def outer():
v = yield from inner()
trace.append("inner returned %r to outer" % v)
yield v
g = outer()
trace.append(next(g))
trace.append(g.throw(ValueError))
assert(trace == [
1,
"inner caught ValueError",
"inner returned 2 to outer",
2,
]) |
JukkaL
changed the title
Full yield support.
Full yield support, including yield expressions
Dec 8, 2014
Ugh, I just hit this bug while reimplementing the parser. Obviously the new parser supports it (though I'm not touching semanal), but I need the tests to pass before switching everything over to actually use the new parser. |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In python 3.X yield is a statement (currently supported) but also an expression.
You can do something like this:
Right now, mypy complains in the expression:
And, also, the Iterator type need the functions send, throw and close, but I think this go in typing project:
The reference is here: https://docs.python.org/3.4/reference/expressions.html#yieldexpr
The text was updated successfully, but these errors were encountered: