-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Opinion: except-pass conflicts with Pythonic EAFP #361
Comments
👍 to remove it, at least from https://github.com/OCA/oca-addons-repo-template/blob/master/src/.pylintrc-mandatory.jinja |
Yeah, I agree to remove it, but this will require an update of all repositories. I would take the occasion to update runboat and GH actions links with such update. |
The reasoning is that, if there's an exception, something should have gone wrong. Thus, there has to be something to be done. Usually, at least, printing a log line explaining the something that is being skipped. The modern pythonic way to avoid the lint error: import contextlib
with contextlib.suppress(IndexError):
# the code that would produce the error and still be OK
recordset[0].unlink() We can leave it in optional checks, as it is somewhat logic what the linter tries to say, although maybe too strict for a requirement. |
@yajo thanks, I can live with replacing my try/except/pass clauses with this. |
Having a warning in pylint-odoo about using
pass
after an exception (except-pass, added in #107) conflicts with the 'easier to ask forgiveness than to ask permission' approach (see https://docs.quantifiedcode.com/python-anti-patterns/readability/asking_for_permission_instead_of_forgiveness_when_working_with_files.html).This approach typically catches specific exceptions which are then
pass
ed. The pylint-odoo recommendation to add a log message can lead to substantial, and overall redundant logging.Would there be interest to remove this check? If so, I could propose a code change.
The text was updated successfully, but these errors were encountered: