[issue27646] yield from expression can be any iterable

New submission from Terry J. Reedy:
https://docs.python.org/3/reference/expressions.html#yield-expressions says "When yield from <expr> is used, it treats the supplied expression as a subiterator. All values produced by that subiterator ...". To me "treats..expression as a subiterator" means that the expression must *be* an iterator, such as returned by iter or calling a generator function. Hence I was surprised upon reading "yield from <non-iterator iterable>" in stdlib code.
I confirmed that this usage is correct by trying
def g():
yield from (1,2)
i = g() next(i), next(i)
(1, 2)
and then reading the PEP380 Formal Semantics, which begins with "_i = iter(EXPR)". Hence I suggest the following replacement for the quote above: "When yield from <expr> is used, the expression must be an iterable. A subiterator is obtained with iter(<expr>). All values produced by that subiterator ...".
Note that 'subiterator' is spelled in the following sentences 'underlying iterable' (which I am not sure I like) and 'sub-iterator' (and 'sub-generator'). I think we should be consistent for at least the two short 'yield from' paragraphs.
---------- assignee: docs@python components: Documentation messages: 271577 nosy: docs@python, terry.reedy priority: normal severity: normal stage: patch review status: open title: yield from expression can be any iterable type: behavior versions: Python 3.5, Python 3.6
_______________________________________ Python tracker report@bugs.python.org http://bugs.python.org/issue27646 _______________________________________

Change by Irit Katriel iritkatriel@yahoo.com:
---------- title: yield from expression can be any iterable -> doc: yield from expression can be any iterable versions: +Python 3.10 -Python 3.5, Python 3.6
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

Change by Terry J. Reedy tjreedy@udel.edu:
---------- keywords: +patch pull_requests: +23373 pull_request: https://github.com/python/cpython/pull/24595
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

Terry J. Reedy tjreedy@udel.edu added the comment:
New changeset 2f9ef514fb24b6a95bd3272885f197752810c107 by Terry Jan Reedy in branch 'master': bpo-27646: Say that 'yield from' expression can be any iterable (GH-24595) https://github.com/python/cpython/commit/2f9ef514fb24b6a95bd3272885f19775281...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- nosy: +miss-islington nosy_count: 2.0 -> 3.0 pull_requests: +23380 pull_request: https://github.com/python/cpython/pull/24602
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

Change by miss-islington mariatta.wijaya+miss-islington@gmail.com:
---------- pull_requests: +23381 pull_request: https://github.com/python/cpython/pull/24603
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset 089a21f7429a3fd3cf78e3779df724757d346d19 by Miss Islington (bot) in branch '3.8': bpo-27646: Say that 'yield from' expression can be any iterable (GH-24595) https://github.com/python/cpython/commit/089a21f7429a3fd3cf78e3779df724757d3...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

miss-islington mariatta.wijaya+miss-islington@gmail.com added the comment:
New changeset 7cc58890b3c16c28360a9abe030258426e89fec1 by Miss Islington (bot) in branch '3.9': bpo-27646: Say that 'yield from' expression can be any iterable (GH-24595) https://github.com/python/cpython/commit/7cc58890b3c16c28360a9abe030258426e8...
----------
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________

Change by Terry J. Reedy tjreedy@udel.edu:
---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.8, Python 3.9
_______________________________________ Python tracker report@bugs.python.org https://bugs.python.org/issue27646 _______________________________________
participants (3)
-
Irit Katriel
-
miss-islington
-
Terry J. Reedy