]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-115911: Ignore PermissionError during import from cwd (#116131)
authorAlex Willmer <alex@moreati.org.uk>
Sun, 26 Jan 2025 19:00:28 +0000 (19:00 +0000)
committerGitHub <noreply@github.com>
Sun, 26 Jan 2025 19:00:28 +0000 (19:00 +0000)
commita8dc6d6d44a141a8f839deb248a02148dcfb509e
tree4a343bb77494d85a5fc7f969ed0d8b8cd248d0de
parent914c232e9391e8e5014b089ba12c75d4a3b0cc7f
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>
Doc/reference/import.rst
Lib/importlib/_bootstrap_external.py
Lib/test/support/os_helper.py
Lib/test/test_importlib/import_/test_path.py
Misc/NEWS.d/next/Core_and_Builtins/2024-02-29-16-55-52.gh-issue-115911.Vnkue_.rst [new file with mode: 0644]