Visitar URL original
bpo-41737: expand doc for NotADirectoryError by akulakov · Pull Request #27471 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223115655/https://github.com/python/cpython/pull/27471
Skip to content
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

Merged
merged 4 commits into from Aug 3, 2021

Conversation

akulakov
Copy link
Contributor

@akulakov akulakov commented Jul 30, 2021 •

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Jul 30, 2021
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
Contributor

@eryksun eryksun Jul 30, 2021

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
Contributor Author

@akulakov akulakov Jul 30, 2021

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
Contributor Author

akulakov commented Jul 30, 2021

@eryksun updated per comment.

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

miss-islington commented Aug 3, 2021

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

bedevere-bot commented Aug 3, 2021

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

@bedevere-bot
Copy link

bedevere-bot commented Aug 3, 2021

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.

None yet

6 participants