[Python-ideas] return from -- breadth of usage

Andrew Barnert abarnert at yahoo.com
Mon Jan 20 23:41:22 CET 2014


On Jan 20, 2014, at 7:39, Chris Angelico <rosuav at gmail.com> wrote:

> If process() happens to return None, then it becomes a tail call, but
> since Python has no way of knowing if this will be the case, it can't
> optimize anything away. (Conversely, if the interpreter knew that
> perform()'s return value was going to be ignored, the same
> optimization could be made, but it can't assume that either.)
> 
> But if 'return from' syntax is added, I don't think it'll be much of
> an issue to put explicit return statements in functions where you know
> it'll always be None.

This is a great argument for not just the idea of the explicit syntax, but also the "return from" name. I hadn't thought about the fact that (non-functional-style) code often ignores a None return value and then returns None, which automatic TCO can't handle, but explicit can. And in that case, "return from" expresses exactly the right thing, just as it does in the recursive case.


More information about the Python-ideas mailing list