mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-115911: Ignore PermissionError during import from cwd (#116131)
Ignore PermissionError when checking cwd during import On macOS `getcwd(3)` can return EACCES if a path component isn't readable, resulting in PermissionError. `PathFinder.find_spec()` now catches these and ignores them - the same treatment as a missing/deleted cwd. Introduces `test.support.os_helper.save_mode(path, ...)`, a context manager that restores the mode of a path on exit. This is allows finer control of exception handling and robust environment restoration across platforms in `FinderTests.test_permission_error_cwd()`. Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
parent
914c232e93
commit
a8dc6d6d44
5 changed files with 58 additions and 5 deletions
|
@ -1244,7 +1244,7 @@ class PathFinder:
|
|||
if path == '':
|
||||
try:
|
||||
path = _os.getcwd()
|
||||
except FileNotFoundError:
|
||||
except (FileNotFoundError, PermissionError):
|
||||
# Don't cache the failure as the cwd can easily change to
|
||||
# a valid directory later on.
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue