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

Eryk Sun report at bugs.python.org
Fri Jul 30 14:53:49 EDT 2021


Eryk Sun <eryksun at gmail.com> added the comment:

> It should be emphasized that it may happen on a **file operation**

I think it's adequately covered by "attempts to open or traverse a non-directory file". The reader should know that opening "/path/to/file/somename.txt" requires traversing the components in the path. So if "file" isn't a directory, raising NotADirectoryError should be expected in POSIX.

---

If someone can verify the behavior on common non-Linux POSIX systems such as macOS, FreeBSD, and OpenBSD, then the wording could be narrowed down to "on most POSIX platforms" instead of "on some platforms". 

For example, given "spam" is a regular file in the current directory, check os.open('spam', os.O_DIRECTORY); os.open('spam/', 0); and os.open('spam/eggs', 0).

----------

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


More information about the Python-bugs-list mailing list