Skip to content

Commit 3a27cb0

Browse files
committed
narrow exceptions guards in SourceFileLoader.set_data
1 parent b039c62 commit 3a27cb0

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

Doc/library/importlib.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,9 @@ ABC hierarchy::
621621
path. Any intermediate directories which do not exist are to be created
622622
automatically.
623623

624-
When writing to the path fails by raising an :class:`OSError`
625-
or a :class:`ValueError`, the exception is not propagated.
624+
When writing to the path fails because the path is read-only
625+
(:const:`errno.EACCES`/:exc:`PermissionError`), do not propagate the
626+
exception. Other exceptions should still be propagated.
626627

627628
.. versionchanged:: 3.4
628629
No longer raises :exc:`NotImplementedError` when called.

Lib/importlib/_bootstrap_external.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,15 +1259,15 @@ def set_data(self, path, data, *, _mode=0o666):
12591259
except FileExistsError:
12601260
# Probably another Python process already created the dir.
12611261
continue
1262-
except (OSError, ValueError) as exc:
1263-
# Could be a permission error, read-only filesystem, or
1264-
# an invalid path name: just forget about writing the data.
1262+
except PermissionError as exc:
1263+
# Could be a permission error, read-only filesystem:
1264+
# just forget about writing the data.
12651265
_bootstrap._verbose_message('could not create {!r}: {!r}',
12661266
parent, exc)
12671267
return
12681268
try:
12691269
_write_atomic(path, data, _mode)
1270-
except (OSError, ValueError) as exc:
1270+
except PermissionError as exc:
12711271
# Same as above: just don't write the bytecode.
12721272
_bootstrap._verbose_message('could not create {!r}: {!r}', path,
12731273
exc)

0 commit comments

Comments
 (0)