Skip to content

Commit b554b2c

Browse files
committed
update docs
1 parent 9aa048d commit b554b2c

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

Doc/library/importlib.rst

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,16 @@ ABC hierarchy::
416416
Loaders that have a file-like storage back-end
417417
that allows storing arbitrary data
418418
can implement this abstract method to give direct access
419-
to the data stored. :exc:`OSError` is to be raised if the *path* cannot
420-
be found. The *path* is expected to be constructed using a module's
421-
:attr:`__file__` attribute or an item from a package's :attr:`__path__`.
419+
to the data stored.
420+
421+
An :exc:`OSError` is to be raised if the *path* cannot be found, and
422+
a :exc:`ValueError` is raised if the *path* cannot be handled (e.g.,
423+
the *path* contains null characters or the *path* is too long). The
424+
*path* is expected to be constructed using a module's :attr:`__file__`
425+
attribute or an item from a package's :attr:`__path__`.
422426

423427
.. versionchanged:: 3.4
424-
Raises :exc:`OSError` instead of :exc:`NotImplementedError`.
428+
Raise :exc:`OSError` by default instead of :exc:`NotImplementedError`.
425429

426430

427431
.. class:: InspectLoader
@@ -551,6 +555,9 @@ ABC hierarchy::
551555

552556
Reads *path* as a binary file and returns the bytes from it.
553557

558+
An :exc:`OSError` is to be raised if the *path* cannot be found, and
559+
a :exc:`ValueError` is raised if the *path* is invalid (e.g., *path*
560+
contains null characters or is too long).
554561

555562
.. class:: SourceLoader
556563

@@ -582,12 +589,13 @@ ABC hierarchy::
582589
- ``'size'`` (optional): the size in bytes of the source code.
583590

584591
Any other keys in the dictionary are ignored, to allow for future
585-
extensions. If the path cannot be handled, :exc:`OSError` is raised.
592+
extensions. If the path cannot be handled, raises an :exc:`OSError`
593+
or a :exc:`ValueError` depending on the reason.
586594

587595
.. versionadded:: 3.3
588596

589597
.. versionchanged:: 3.4
590-
Raise :exc:`OSError` instead of :exc:`NotImplementedError`.
598+
Raise :exc:`OSError` by default instead of :exc:`NotImplementedError`.
591599

592600
.. method:: path_mtime(path)
593601

@@ -597,20 +605,21 @@ ABC hierarchy::
597605
.. deprecated:: 3.3
598606
This method is deprecated in favour of :meth:`path_stats`. You don't
599607
have to implement it, but it is still available for compatibility
600-
purposes. Raise :exc:`OSError` if the path cannot be handled.
608+
purposes. If the path cannot be handled, raises an :exc:`OSError`
609+
or a :exc:`ValueError` depending on the reason.
601610

602611
.. versionchanged:: 3.4
603-
Raise :exc:`OSError` instead of :exc:`NotImplementedError`.
612+
Raise :exc:`OSError` by default instead of :exc:`NotImplementedError`.
604613

605614
.. method:: set_data(path, data)
606615

607616
Optional abstract method which writes the specified bytes to a file
608617
path. Any intermediate directories which do not exist are to be created
609618
automatically.
610619

611-
When writing to the path fails because the path is read-only
612-
(:const:`errno.EACCES`/:exc:`PermissionError`), do not propagate the
613-
exception.
620+
When writing to the path fails by raising an :class:`OSError` (e.g.,
621+
the path is read-only (:const:`errno.EACCES`/:exc:`PermissionError`)
622+
or a :class:`ValueError`, the exception is not propagated.
614623

615624
.. versionchanged:: 3.4
616625
No longer raises :exc:`NotImplementedError` when called.

0 commit comments

Comments
 (0)