You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In python 3.X yield is a statement (currently supported) but also an expression.
You can do something like this:
fromtypingimportIteratordeftest_yield() ->Iterator[int]:
value=1try:
value=yieldvalue# Here is the yield expressionyieldvalueyieldvalue+1exceptTypeErrorase:
print(e)
gen=test_yield()
x1=next(gen)
x2=gen.send(2)
print(x1) # 1print(x2) # 2gen.throw(TypeError, 'ERROR')
gen.close()
Right now, mypy complains in the expression:
_program.py: In function "test_yield":
_program.py, line 6: Parse error before "value"
And, also, the Iterator type need the functions send, throw and close, but I think this go in typing project:
_program.py, line 14: Iterator[int] has no attribute "send"
_program.py, line 17: Iterator[int] has no attribute "throw"
_program.py, line 18: Iterator[int] has no attribute "close"
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.
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: