[issue41737] Improper NotADirectoryError when opening a file in a fake directory

Danny Lin report at bugs.python.org
Tue Oct 20 09:54:41 EDT 2020


Danny Lin <danny0838 at gmail.com> added the comment:

By writing "except FileNotFoundError:", the intention is to catch an error when the file being opened is not found, and don't catch an error for other cases, such as an existing file without adequate permission. Writing "except OSError:" catches just too much cases including unwanted ones.

As they are not equivalent, you cannot say that the latter is the "correct" way for the former.

And you totally omitted the argument for the inadequate documentation for NotADirectoryError. It says NotADirectoryError is raises when a DIRECTORY operation is requested, and does not cover the case of opening a file.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41737>
_______________________________________


More information about the Python-bugs-list mailing list