=== on 28 Jan 2020, 18:01:07 Nicolas Harraudeau wrote:
\[~pierre-loup.tristant] I don't think that we can apply this rule for Python as it is specified. Contrary to other languages, python follows the EAFP (easier to ask for forgiveness than permission) coding style. This means that trying an operation and catching exceptions is preferred to checking beforehand that an operation is possible. Thus we would probably raise a lot of issues.


Example of good practice https://docs.quantifiedcode.com/python-anti-patterns/readability/asking_for_permission_instead_of_forgiveness_when_working_with_files.html#best-practice[from QuantifiedCode]:

----
import os

try:
    os.unlink("file.txt")
# raised when file does not exist
except OSError:
    pass
----

=== on 29 Jan 2020, 11:15:47 Nicolas Harraudeau wrote:
I think we could improve this rule by focusing on specific security exceptions. Example: Django's https://docs.djangoproject.com/en/3.0/ref/exceptions/#permissiondenied[``++PermissionDenied++``] exception, but this might be a Security Hotspot instead.

include::../comments-and-links.adoc[]
