On 22 April 2018 at 03:41, Steven D'Aprano <st...@pearwood.info> wrote: > We *already* have the rule that the outermost iterable is special, > except it isn't a rule precisely, since (as far as I know) it isn't > documented anywhere, nor was it ever planned as a feature.
It's a deliberate feature of generator expressions: https://www.python.org/dev/peps/pep-0289/#the-details Covered in the language reference here: https://docs.python.org/3/reference/expressions.html#generator-expressions It's then inherited by comprehensions through the intentional semantic equivalences between: [x for x in iterable] <-> list(x for x in iterable) {x for x in iterable} <-> set(x for x in iterable) {k(x):v(x) for x in iterable} <-> set((k(x), v(x) for x in iterable)) The consequences of those equivalences weren't historically spelled out in the language reference, but we fixed that omission when deprecating the use of "yield" & "yield from" in comprehensions for 3.7: https://github.com/python/cpython/commit/73a7e9b10b2ec9636e3c6396cf7b3695f8ed1856 (we had to in order to explain why you *can* still use "yield" and "yield from" in the outermost iterable - it's because the restriction only applies to the implicitly nested scope). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com