bpo-32248: Introduce the concept of Loader.get_resource_reader() (GH-… · python/cpython@bca4218 · GitHub
Skip to content

Commit bca4218

Browse files
authored
bpo-32248: Introduce the concept of Loader.get_resource_reader() (GH-5108)
1 parent 5b76bdb commit bca4218

4 files changed

Lines changed: 57 additions & 13 deletions

File tree

Doc/library/importlib.rst

Lines changed: 24 additions & 7 deletions

Doc/whatsnew/3.7.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ importlib.resources
328328
This module provides several new APIs and one new ABC for access to, opening,
329329
and reading *resources* inside packages. Resources are roughly akin to files
330330
inside of packages, but they needn't be actual files on the physical file
331-
system. Module loaders can implement the
332-
:class:`importlib.abc.ResourceReader` ABC to support this new module's API.
331+
system. Module loaders can provide :class:`importlib.abc.ResourceReader`
332+
implementations to support this new module's API.
333333

334334

335335
Improved Modules
@@ -429,6 +429,12 @@ and the ``--directory`` to the command line of the module :mod:`~http.server`.
429429
With this parameter, the server serves the specified directory, by default it uses the current working directory.
430430
(Contributed by Stéphane Wirtel and Julien Palard in :issue:`28707`.)
431431

432+
importlib
433+
---------
434+
435+
The :class:`importlib.abc.ResourceReader` ABC was introduced to
436+
support the loading of resource from packages.
437+
432438
locale
433439
------
434440

@@ -761,6 +767,9 @@ Deprecated
761767

762768
- The :mod:`macpath` is now deprecated and will be removed in Python 3.8.
763769

770+
- The :class:`importlib.abc.ResourceLoader` ABC has been deprecated in
771+
favour of :class:`importlib.abc.ResourceReader`.
772+
764773

765774
Changes in the C API
766775
--------------------
@@ -785,8 +794,8 @@ Windows Only
785794
been used. If the specified version is not available py.exe will error exit.
786795
(Contributed by Steve Barnes in :issue:`30291`.)
787796

788-
- The launcher can be run as "py -0" to produce a list of the installed pythons,
789-
*with default marked with an asterix*. Running "py -0p" will include the paths.
797+
- The launcher can be run as ``py -0`` to produce a list of the installed pythons,
798+
*with default marked with an asterisk*. Running ``py -0p`` will include the paths.
790799
If py is run with a version specifier that cannot be matched it will also print
791800
the *short form* list of available specifiers.
792801
(Contributed by Steve Barnes in :issue:`30362`.)

Lib/importlib/abc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,14 @@ def set_data(self, path, data):
342342
_register(SourceLoader, machinery.SourceFileLoader)
343343

344344

345-
class ResourceReader(Loader):
345+
class ResourceReader:
346346

347-
"""Abstract base class for loaders to provide resource reading support."""
347+
"""Abstract base class to provide resource-reading support.
348+
349+
Loaders that support resource reading are expected to implement
350+
the ``get_resource_reader(fullname)`` method and have it either return None
351+
or an object compatible with this ABC.
352+
"""
348353

349354
@abc.abstractmethod
350355
def open_resource(self, resource):
Lines changed: 13 additions & 0 deletions

0 commit comments

Comments
 (0)