-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-37478: Specify possible exceptions for os.chdir() #14611
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3e4e456
Merge pull request #1 from python/master
aeros 1094492
Add possible exceptions to os.chdir()
aeros 4780942
"method" to "function"
aeros c0beb06
Removed added whitespace
aeros acbddb7
📜🤖 Added by blurb_it.
blurb-it[bot] f1e3533
Whitespace fix
aeros 7e4953f
Update os.rst
terryjreedy 8b515b3
Fix exception tag
aeros 4b65eeb
add space back and trigger retest
terryjreedy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add possible exceptions to os.chdir()
- Loading branch information
commit 1094492fde7e3346079fc714fa79dd6fd625c9e4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Another common error is
PermissionError
. Also, in Windows if a path component exceeds the filesystem's maximum allowed name length or if it contains reserved characters,chdir
raisesOSError
witherrno.EINVAL
.It's also noteworthy that
ValueError
is raised if there's a null ("\x00"
) in the path. However, it might be better to discuss this generally in the section about filenames.Uh oh!
There was an error while loading. Please reload this page.
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.
@eryksun Thanks for the feedback and suggestions. Since
PermissionError
falls under the category ofOSError
exceptions, I'm not entirely certain as whether or not it should be explicitly mentioned. The purpose of that section was primarily to mention that the function could raiseOSError
exceptions and just to provide a couple of examples rather than explicitly state every possible type ofOSError
which could be encountered. The section could get excessively verbose rather quickly, see https://docs.python.org/3/library/errno.html#module-errno.However,
PermissionError
might be common enough to warrant mentioning it, I'll have to see what the others think. As for theValueError
behavior, since that would apply universally to any file path argument, it should probably be in a more general section (such as the filename section, as you mentioned) rather than in a specific function description.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 added PermissionError, leaving ValueError for another issue. Can this function raise OSError itself or only subclasses? I assumed the later in my edit.
This function can raise :exc:
OSError
subclasses such as:exc:
FileNotFoundError
, :exc:PermissionError
, and exc:NotADirectoryError
.Uh oh!
There was an error while loading. Please reload this page.
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.
@terryjreedy Specifically, the function raises the subclasses when it comes to

FileNotFoundError
andNotADirectoryError
, so your assumption was correct. As far as I am aware, it can't directly raiseOSError
. I verified this is the case forFileNotFoundError
andNotADirectoryError
in Python 3.9:Uh oh!
There was an error while loading. Please reload this page.
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.
On the commit message for
Fix exception tag
, it should bePermissionError
instead ofNotADirectoryError
.Edit: Not sure if I can retroactively change the commit message, or if that has to be done by a core dev. Let me know if there's a way for me to fix it.
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.
As I said in my previous comment, in Windows it can raise
OSError
witherrno == EINVAL
(from WINAPIwinerror == ERROR_INVALID_NAME
) if a path component exceeds the maximum allowed name length or contains characters reserved by the filesystem such as control characters (1-31) and the 5 wildcard characters (*?"<>
). Python lacks something like anInvalidArgumentError
subclass for this case. This is a generic filename error like the case with embedded null characters andValueError
, so maybe a subsection can briefly discuss invalid filenames in Windows.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.
@aeros167 The within PR commit messages do not matter after the fact as commits are squished into 1 for the merge.
@eryksun I commited too soon without fully understanding. I will do a followup PR adding 'and' to say 'OSError and subclasses'. This should be good enough for this issue.