mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-107732: Mention dir support in importlib.resources docs (GH-107734) (#109058)
gh-107732: Mention dir support in importlib.resources docs (#107734)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
(cherry picked from commit 9f0c0a46f0
)
Co-authored-by: Shahriar Heidrich <smheidrich@weltenfunktion.de>
This commit is contained in:
parent
c9dc2bc0de
commit
5ca2a68bbe
2 changed files with 14 additions and 5 deletions
|
@ -82,19 +82,22 @@ for example, a package and its resources can be imported from a zip file using
|
|||
.. function:: as_file(traversable)
|
||||
|
||||
Given a :class:`~importlib.resources.abc.Traversable` object representing
|
||||
a file, typically from :func:`importlib.resources.files`, return
|
||||
a context manager for use in a :keyword:`with` statement.
|
||||
a file or directory, typically from :func:`importlib.resources.files`,
|
||||
return a context manager for use in a :keyword:`with` statement.
|
||||
The context manager provides a :class:`pathlib.Path` object.
|
||||
|
||||
Exiting the context manager cleans up any temporary file created when the
|
||||
resource was extracted from e.g. a zip file.
|
||||
Exiting the context manager cleans up any temporary file or directory
|
||||
created when the resource was extracted from e.g. a zip file.
|
||||
|
||||
Use ``as_file`` when the Traversable methods
|
||||
(``read_text``, etc) are insufficient and an actual file on
|
||||
(``read_text``, etc) are insufficient and an actual file or directory on
|
||||
the file system is required.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
.. versionchanged:: 3.12
|
||||
Added support for ``traversable`` representing a directory.
|
||||
|
||||
|
||||
Deprecated functions
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -631,6 +631,12 @@ fractions
|
|||
* Objects of type :class:`fractions.Fraction` now support float-style
|
||||
formatting. (Contributed by Mark Dickinson in :gh:`100161`.)
|
||||
|
||||
importlib.resources
|
||||
-------------------
|
||||
|
||||
* :func:`importlib.resources.as_file` now supports resource directories.
|
||||
(Contributed by Jason R. Coombs in :gh:`97930`.)
|
||||
|
||||
inspect
|
||||
-------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue