New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return value directly from the try block and avoid a variable #4342
Return value directly from the try block and avoid a variable #4342
Conversation
I'm personally -1 as when |
I think that's an invalid assumption to make. This behavior that the For the case when the length of the Apart from that, I think the given patch fixes a potential bug. Consider the following code (from
If an exception occurs while opening |
I do not disagree with what id does and wether it is logic or not. I tend to take care about what people will think the block of code does when reading it in a few years. The second point seem valid though, would there be a way to auto test that ? |
The behaviour of a return statement in a finally block might be standard, but it's not obvious - when we're reading code, we'll generally assume that the first return statement it reaches is what defines the return value, and finally blocks are essentially cleanup. In general, we want both readable code and tests, not one or the other. Tests won't pick up all problems. In the example you give, if an exception is raised, the code in the finally block will run, and then the exception will go up the stack, since there's nothing there to catch it. It wouldn't reach the return statement, if I'm reading it correctly. I'm inclined to say, again, that we'd accept new code written either way, but we're not interested in changing things like this without a fairly clear rationale. |
On Sun, Oct 6, 2013 at 11:35 PM, Matthias Bussonnier <
|
On Sun, Oct 6, 2013 at 11:36 PM, Thomas Kluyver notifications@github.comwrote:
|
Thanks. In general, |
I am +0 as well. |
OK, merging this one, just to clear it up. If the finally blocks get more complex, they can be changed back if it seems appropriate. |
…ignment Return value directly from the try block and avoid a variable
…ble-assignment Return value directly from the try block and avoid a variable
Avoid another temporary variable assignment by directly returning the value from the try block. The finally block will be executed nevertheless.