Re: [Python-Dev] [Python-checkins] cpython (3.4): Issue #23840: tokenize.open() now closes the temporary binary file on error to
On 2015-05-26 12:26 AM, Terry Reedy wrote:
+ try: + encoding, lines = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text + except: + buffer.close() + raise
Please do not add bare 'except:'. If you mean 'except BaseException:', say so.
try..finally would be even better. Yury
What is wrong with "except:" in this specific case?
Victor
Le mardi 26 mai 2015, Yury Selivanov
On 2015-05-26 12:26 AM, Terry Reedy wrote:
+ try:
+ encoding, lines = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text + except: + buffer.close() + raise
Please do not add bare 'except:'. If you mean 'except BaseException:', say so.
try..finally would be even better.
Yury _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.co...
On Tue, 26 May 2015 08:20:01 +0200, Victor Stinner
What is wrong with "except:" in this specific case?
Nothing is wrong with it from a technical standpoint. However, if we use 'except BaseException' that makes it clear that someone has thought about it and decided that all exceptions should be caught, as opposed to it being legacy code or a programming mistake.
On 2015-05-26 12:26 AM, Terry Reedy wrote:
+ try: + encoding, lines = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text + except: + buffer.close() + raise
Please do not add bare 'except:'. If you mean 'except BaseException:', say so.
On 26.05.15 08:33, Yury Selivanov wrote:
On 2015-05-26 12:26 AM, Terry Reedy wrote:
+ try: + encoding, lines = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text + except: + buffer.close() + raise
Please do not add bare 'except:'. If you mean 'except BaseException:', say so.
try..finally would be even better.
No, finally is not correct there. buffer shouldn't be closed if no exception is raised. And this is one of the cases in which bare 'except:' is absolutely legal.
2015-05-26 8:44 GMT+02:00 Serhiy Storchaka
No, finally is not correct there. buffer shouldn't be closed if no exception is raised.
Yep. The binary file must only be closed in case of error, as written in the commit message.
And this is one of the cases in which bare 'except:' is absolutely legal.
The "except: <cleanup code>; raise" is common in the Python stdlib. Victor
On 2015-05-26 3:54 AM, Victor Stinner wrote:
2015-05-26 8:44 GMT+02:00 Serhiy Storchaka
: No, finally is not correct there. buffer shouldn't be closed if no exception is raised. Yep. The binary file must only be closed in case of error, as written in the commit message.
Right. My bad, sorry Victor ;) Yury
participants (4)
-
R. David Murray
-
Serhiy Storchaka
-
Victor Stinner
-
Yury Selivanov