Skip to content

Commit 9f0c0a4

Browse files
smheidrichAA-Turnerhugovk
authored
gh-107732: Mention dir support in importlib.resources docs (#107734)
Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent f9bd6e4 commit 9f0c0a4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Doc/library/importlib.resources.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,18 @@ for example, a package and its resources can be imported from a zip file using
8282
.. function:: as_file(traversable)
8383

8484
Given a :class:`~importlib.resources.abc.Traversable` object representing
85-
a file, typically from :func:`importlib.resources.files`, return
86-
a context manager for use in a :keyword:`with` statement.
85+
a file or directory, typically from :func:`importlib.resources.files`,
86+
return a context manager for use in a :keyword:`with` statement.
8787
The context manager provides a :class:`pathlib.Path` object.
8888

89-
Exiting the context manager cleans up any temporary file created when the
90-
resource was extracted from e.g. a zip file.
89+
Exiting the context manager cleans up any temporary file or directory
90+
created when the resource was extracted from e.g. a zip file.
9191

9292
Use ``as_file`` when the Traversable methods
93-
(``read_text``, etc) are insufficient and an actual file on
93+
(``read_text``, etc) are insufficient and an actual file or directory on
9494
the file system is required.
9595

9696
.. versionadded:: 3.9
97+
98+
.. versionchanged:: 3.12
99+
Added support for ``traversable`` representing a directory.

Doc/whatsnew/3.12.rst

+6
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ fractions
630630
* Objects of type :class:`fractions.Fraction` now support float-style
631631
formatting. (Contributed by Mark Dickinson in :gh:`100161`.)
632632

633+
importlib.resources
634+
-------------------
635+
636+
* :func:`importlib.resources.as_file` now supports resource directories.
637+
(Contributed by Jason R. Coombs in :gh:`97930`.)
638+
633639
inspect
634640
-------
635641

0 commit comments

Comments
 (0)