-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Documentation
As pointed out in a thread on the Ideas forum, importlib.resources gained support for extracting/returning whole directories as resources via its as_file() function in Python 3.12.
But the docs make no mention of this and in fact heavily suggest the opposite (emphasis mine):
importlib.resources.as_file(traversable)
Given a Traversable object representing a file, typically from importlib.resources.files(), return a context manager for use in a with statement. [...]Exiting the context manager cleans up any temporary file 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 the file system is required.
This should probably be changed to reflect the fact that it can now handle directories as well, not just individual files.
Especially important because being able to extract/return whole directories was a feature that importlib.resources lacked for quite a while compared to its now-deprecated predecessor pkg_resources, so not pointing out that this works now can make people remain hesitant to make the switch.
PR incoming.