[issue47147] Allow `return yield from`

2022-04-02 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I concur with Terry.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-04-02 Thread Patrick Reader


Patrick Reader  added the comment:

As the one who wrote the code, I can guarantee you that the StopIteration value 
is not always None.

But I understand your point that for most other users it is always None, and 
therefore having special syntax might be misleading.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-04-01 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I think that this should be closed as rejected, and that Patrick should remove 
the 'return's that are in front of 'yield from ...'.  Then 'yield from x' will 
be a statement, not an expression, and the ()s will not be needed, as they are 
used to differentiate yield expressions from yield statements. Generator 
functions return generators, not return expressions.  The latter are only used 
for the StopIteration .value attribute, which I believe is always None for 
Patrick's code and in any case is never used.  So his code should run the same 
without these 'return's.

The exception for '= yield ...' is similar to '= a, ...' not needing ()s.  This 
is the only exception for yield expressions because this is normally the only 
place a yield expression should be used by itself instead of with other 
operators or functions, where ()s are needed.

The python-ideas thread archive is at
https://mail.python.org/archives/list/python-id...@python.org/thread/L6XRQ5YWAE535JGZH2MF2TD32C65K5ZI/

Andrew Svetlov objected (-1) because to him ()s make the statement more 
readable.

Michael Smith got to the real problem, which is that one should not be using 
"return (yield from x)" unless one is accessing a possibly non-None value 
attribute of the implicitly raised StopIteration exception.

I oppose adding a second no-() exception for such rare (and somewhat confusing) 
expert uses. 

In a generator function, the return value is a generator based on the entire 
body of the function.  Any return statement value becomes the value attribute 
of the StopIteration raised when the generator is exhausted.  In other words, 
'return x' in this context translates to "raise StopIteration(x)' (which is 
illegal to write directly). I am pretty sure that in your code, the value of 
'yield from func' is always None.  In any case, StopIteration().value is never 
used.

To illustrate:

def g0():
return (yield from ())  # Immediately raise StopIteration(None).

try: next(g0())
except StopIteration as e:
print(e.value)

# Prints 'None'.

--
nosy: +terry.reedy
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-03-28 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

In general, anything changing the python syntax needs to be discussed in the 
mailing lists and it may likely need a PEP as well, even if is minor. This is 
because this has consequences rippling the whole ecosystem, from IDEs to other 
parsers and this need to be discussed, and communicated in a better forum than 
this.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-03-28 Thread Patrick Reader


Patrick Reader  added the comment:

Ok, will do, but what is the bar for a feature to need to go to the mailing 
lists first? I thought as this was a relatively minor one it wouldn't need to. 
Is it just because it's an actual syntax change?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-03-28 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

Please, submit an email to python-ideas or python-dev first as this need to be 
discussed in the mailing lists.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47147] Allow `return yield from`

2022-03-28 Thread Patrick Reader


New submission from Patrick Reader :

I would like to be able to use a `yield from` expression in a `return` 
statement without parentheses, as a small quality of life tweak, i.e.:

return yield from gen

instead of

return (yield from gen)

I think this makes sense, since `yield from` can be used on the right-hand-side 
of an assignment, which accepts any expression, and so should `return`.

Here is a medium-sized real-world example of where I'm using this, where it 
would be nice to allow `return yield from`: 
https://gist.github.com/pxeger/48f97484364bf0b43dee974a8f0f4265

--
components: Parser
messages: 416198
nosy: lys.nikolaou, pablogsal, pxeger
priority: normal
severity: normal
status: open
title: Allow `return yield from`
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com