Message334190
> steven your generator example is exactly what I wanted to do; looks
> like I'm upgrading to Python 3.8 for the new assignment syntax.
Sorry to have mislead you, but I don't think it will do what I thought.
After giving it some more thought, I decided to test it (at least as
much of it as possible). There's no local assignment here but you can
see that the behaviour is not what I had assumed:
py> def inner():
... yield from (1, 2)
... return -1
...
py> def outer():
... for x in (yield from inner()):
... yield 100+x
...
py> for x in outer():
... print(x)
...
1
2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in outer
TypeError: 'int' object is not iterable
In hindsight, this behaviour is logical. But I think it means that there
is no way to do what you want using a for-loop.
> I was actually expecting the SyntaxError to be raised at runtime which
> would be a pretty large behavior change
Not *entirely* unprecedented though, as you can get runtime SyntaxErrors
from calling compile(), eval() or exec(). But I think some other class
of exception would be better, since the problem isn't actually a syntax
error. |
|
Date |
User |
Action |
Args |
2019-01-21 22:56:20 | steven.daprano | set | recipients:
+ steven.daprano, terry.reedy, Bryan Koch, greg.ewing |
2019-01-21 22:56:18 | steven.daprano | link | issue35756 messages |
2019-01-21 22:56:18 | steven.daprano | create | |
|