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

alex23 wuwei23 at gmail.com
Wed Dec 26 11:58:27 CET 2012


On Dec 26, 7:55 pm, Ram Rachum <r... at rachum.com> wrote:
> Alex: I'm getting the feeling that you misunderstand what I'm proposing
> here. I'm proposing that the return value will be accessible in the
> `finally` clause. In a similar (if shorter) way that the exception info is
> available by using `sys.exc_info()`.

I get what you're saying. What you haven't shown is how introducing
'return value' semantics to try/finally blocks does anything other
than make them more confusing to people. Functions have return values.
Decorators wrap functions and can thus be used to pre- or post-process
the in/outputs for the function. This is clearly defined and a well
known approach to your problem. The onus is on you to show how turning
try/finally into a kitchen-sink of behaviour will improve the
language, preferably without recourse to what you "think" or "feel".

A concrete use-case would help here, but I'm 100% convinced that
whatever you come up with, there'll be a better solution using
decorators that works right now.



More information about the Python-ideas mailing list