Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
> 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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35756> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com