Closed DimitriPapadopoulos closed 2 years ago
About Except block handles 'BaseException':
All exception classes in Python derive from
BaseException
.BaseException
has three important subclasses,Exception
from which all errors and normal exceptions derive,KeyboardInterrupt
which is raised when the user interrupts the program from the keyboard andSystemExit
which is raised by thesys.exit()
function to terminate the program.Since
KeyboardInterrupt
andSystemExit
are special they should not be grouped together with otherException
classes.Catching
BaseException
, rather than its subclasses may prevent proper handling ofKeyboardInterrupt
orSystemExit
. It is easy to catchBaseException
accidentally as it is caught implicitly by an emptyexcept
: statement.
@DimitriPapadopoulos a few questions / requests:
Actually the current change is not aesthetic: before the change the code catches everything including BaseException
, after the change it catches only subclasses of Exception
. The issue raised by LGTM.com is thus fixed:
Catching
BaseException
, rather than its subclasses may prevent proper handling ofKeyboardInterrupt
orSystemExit
. It is easy to catchBaseException
accidentally as it is caught implicitly by an emptyexcept:
statement.
That said, I totally agree with catching only the intended exceptions, but that can be quite difficult in Python after the fact. I'd rather do that in a different PR. This PR fixes the KeyboardInterrupt
/SystemExit
issue.
I don't think it's possible to automate anything here. Tools like LGTM.com or DeepSource.io do assist in code reviewing, but we cannot let them decide blindly - yet?
I must have misunderstood you. I believe you want automatic LGTM reporting (not automatically fixing alerts). Of course it is possible to have a CI job that checks new PRs and raises alerts. Here is the relevant page:
Thanks for the details! I will have to think about it - I'm usually pretty conservative about giving bots write access to PRs (or anything for that matter) and I'm not sure the benefits outweigh the risk. These are pretty small, trivial things.
Yes, many alerts are trivial, but it does happen that they hide real issues.
Description
Fixes most of the remaining LGTM recommendations: https://lgtm.com/projects/g/pydicom/deid/alerts/?severity=recommendation
Checklist
Open questions
The remaining recommendations should probably not be fixed.