Re: [Python-ideas] Allow accessing return value inside finally clause

On 26 Dec, 10:44, Ram Rachum <r...@rachum.com> wrote:
I don't think that this makes Python less clear;
How can you possibly say this? You've changed the `finally` clause from _guaranteed_ execution to something utterly inconsistent. In fact, finally blocks would need to have _more_ code to guard against all of the different execution models you're proposing here. I'm not sure why you think forcing me to write more & less obvious code in a finally block is a better trade off than you making clear, explicit use of decorators. Ambiguity does not equate to clarity. Less typing doesn't either. Creating small re-usable pieces of code that do the "hard work" for you, however, _is a lot more clear_.
The behaviour of `for..else` doesn't change based on arbitrary conditions, whereas what you propose is that the finally blocks behaviour is _fundamentally_ different depending on whether the try block is fully executed or not, whether an exception is raised or not. This is absolutely not the same thing, and trying to pass this concern off as "confusing to newbies" is rather disingenuous. The behaviour would be _confusing to everybody_. This is not a valid cost to save you from having to type a few more keystrokes to decorate the return value.
participants (2)
-
alex23
-
Jasper St. Pierre