Skip to content

bpo-41737: expand doc for NotADirectoryError#27471

Merged
ambv merged 4 commits into
python:mainfrom
akulakov:41737-Expand-not-a-directory-error-doc
Aug 3, 2021
Merged

bpo-41737: expand doc for NotADirectoryError#27471
ambv merged 4 commits into
python:mainfrom
akulakov:41737-Expand-not-a-directory-error-doc

Conversation

@akulakov
Copy link
Copy Markdown
Contributor

@akulakov akulakov commented Jul 30, 2021

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Jul 30, 2021
Comment thread Doc/library/exceptions.rst Outdated
Comment on lines +694 to +696
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.
Copy link
Copy Markdown
Contributor

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_DIRECTORY was 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

Copy link
Copy Markdown
Contributor Author

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!

@akulakov
Copy link
Copy Markdown
Contributor Author

@eryksun updated per comment.

@ambv ambv merged commit f7c23a9 into python:main Aug 3, 2021
@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @akulakov for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link
Copy Markdown

GH-27576 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Aug 3, 2021
@bedevere-bot
Copy link
Copy Markdown

GH-27577 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 3, 2021
(cherry picked from commit f7c23a9)

Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 3, 2021
(cherry picked from commit f7c23a9)

Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
ambv pushed a commit that referenced this pull request Aug 3, 2021
(cherry picked from commit f7c23a9)

Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
miss-islington added a commit that referenced this pull request Aug 3, 2021
(cherry picked from commit f7c23a9)

Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants