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
bpo-41737: expand doc for NotADirectoryError #27471
bpo-41737: expand doc for NotADirectoryError #27471
Conversation
Doc/library/exceptions.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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