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

On 26 Dec, 08:06, Ram Rachum <r...@rachum.com> wrote:
I initially responded to say "use a decorator", but you're already aware of the common pattern for dealing with this, and yet you'd rather the language change instead?
People already struggle with understanding the semantics of try/ finally - you yourself demonstrated this in your first post by not being away that the 'return value' may not be set - and you want to make it _more_ magic? You're a programmer. At the end of the day, you're going to have to do _some_ "heavy" lifting by yourself. Assign your return values to an object that performs the post-processing on demand. Create a context manager that does it when it exits. Write a loop to decorate your functions if typing @decorator is so strenuous. Making Python less clear to save yourself some typing isn't a decent trade off.
participants (1)
-
alex23