bpo-41737: expand doc for NotADirectoryError#27471
Conversation
| on something which is not a directory. Can also be raised on a file operation | ||
| that involves reading a directory, in which case this error may indicate that | ||
| path is either not a directory or does not exist. |
There was a problem hiding this comment.
I'd emphasize that NotADirectoryError can be raised by a file operation that tries to open or traverse a non-directory file or symlink to a non-directory file as if it were a directory. The concrete actions "open" and "traverse" flesh out the more generic phrasing "directory operation".
The case of a non-existing path component is unrelated. That should fail with ENOENT, i.e. FileNotFoundError.
Here are some particular cases from POSIX that fail with ENOTDIR:
- A component of the path prefix (i.e. excluding the last component and trailing slash characters) names an existing file that is neither a directory nor a symbolic link to a directory. System calls:
open,stat,mkdir - The path argument contains at least one non-slash character and ends with one or more trailing slash characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory. System calls:
open,stat O_DIRECTORYwas specified and the path argument resolves to a non-directory file. System calls:open- A component of dirname names an existing file that is neither a directory nor a symbolic link to a directory. System calls:
opendir
There was a problem hiding this comment.
I've misread the bug report in respect to non-existent path, thanks for catching that!
|
@eryksun updated per comment. |
|
GH-27576 is a backport of this pull request to the 3.10 branch. |
|
GH-27577 is a backport of this pull request to the 3.9 branch. |
(cherry picked from commit f7c23a9) Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
(cherry picked from commit f7c23a9) Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
https://bugs.python.org/issue41737