GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.12] gh-116608: undeprecate functional importlib.resources API by graingert · Pull Request #132206 · python/cpython

[3.12] gh-116608: undeprecate functional importlib.resources API #132206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Yhg1s merged 3 commits into python:3.12 from graingert:undeprecate-functional-api-3-12
Apr 8, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

[3.12] gh-116608: undeprecate functional importlib.resources API #132206

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
fda1037
gh-116608: undeprecate functional importlib.resources API
graingert Apr 7, 2025
c4db7b3
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 7, 2025
02ac21b
Merge branch '3.12' into undeprecate-functional-api-3-12
graingert Apr 7, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

51 changes: 17 additions & 34 deletions 51 Doc/library/importlib.resources.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ for example, a package and its resources can be imported from a zip file using
Added support for *traversable* representing a directory.


Deprecated functions
^^^^^^^^^^^^^^^^^^^^
Functional API
^^^^^^^^^^^^^^

An older, deprecated set of functions is still available, but is
scheduled for removal in a future version of Python.
An older, previously deprecated set of functions is still available.
The main drawback of these functions is that they do not support
directories: they assume all resources are located directly within a *package*.

Expand All @@ -116,8 +115,6 @@ directories: they assume all resources are located directly within a *package*.

The ``Package`` type is defined as ``Union[str, ModuleType]``.

.. deprecated:: 3.12


.. data:: Resource

Expand All @@ -138,11 +135,9 @@ directories: they assume all resources are located directly within a *package*.
sub-resources (i.e. it cannot be a directory). This function returns a
``typing.BinaryIO`` instance, a binary I/O stream open for reading.

.. deprecated:: 3.11

Calls to this function can be replaced by::
This function is roughly equivalent to::

files(package).joinpath(resource).open('rb')
files(package).joinpath(resource).open('rb')


.. function:: open_text(package, resource, encoding='utf-8', errors='strict')
Expand All @@ -159,11 +154,9 @@ directories: they assume all resources are located directly within a *package*.
This function returns a ``typing.TextIO`` instance, a text I/O stream open
for reading.

.. deprecated:: 3.11
This function is roughly equivalent to::

Calls to this function can be replaced by::

files(package).joinpath(resource).open('r', encoding=encoding)
files(package).joinpath(resource).open('r', encoding=encoding)


.. function:: read_binary(package, resource)
Expand All @@ -177,11 +170,9 @@ directories: they assume all resources are located directly within a *package*.
sub-resources (i.e. it cannot be a directory). This function returns the
contents of the resource as :class:`bytes`.

.. deprecated:: 3.11

Calls to this function can be replaced by::
This function is roughly equivalent to::

files(package).joinpath(resource).read_bytes()
files(package).joinpath(resource).read_bytes()


.. function:: read_text(package, resource, encoding='utf-8', errors='strict')
Expand All @@ -196,11 +187,9 @@ directories: they assume all resources are located directly within a *package*.
have the same meaning as with built-in :func:`open`. This function
returns the contents of the resource as :class:`str`.

.. deprecated:: 3.11
This function is roughly equivalent to::

Calls to this function can be replaced by::

files(package).joinpath(resource).read_text(encoding=encoding)
files(package).joinpath(resource).read_text(encoding=encoding)


.. function:: path(package, resource)
Expand All @@ -217,11 +206,9 @@ directories: they assume all resources are located directly within a *package*.
within *package*; it may not contain path separators and it may not have
sub-resources (i.e. it cannot be a directory).

.. deprecated:: 3.11

Calls to this function can be replaced using :func:`as_file`::
This function is roughly equivalent to ::

as_file(files(package).joinpath(resource))
as_file(files(package).joinpath(resource))


.. function:: is_resource(package, name)
Expand All @@ -232,11 +219,9 @@ directories: they assume all resources are located directly within a *package*.
*package* is either a name or a module object which conforms to the
``Package`` requirements.

.. deprecated:: 3.11
This function is roughly equivalent to::

Calls to this function can be replaced by::

files(package).joinpath(resource).is_file()
files(package).joinpath(resource).is_file()


.. function:: contents(package)
Expand All @@ -248,8 +233,6 @@ directories: they assume all resources are located directly within a *package*.
*package* is either a name or a module object which conforms to the
``Package`` requirements.

.. deprecated:: 3.11

Calls to this function can be replaced by::
This function is roughly equivalent to::

(resource.name for resource in files(package).iterdir() if resource.is_file())
(resource.name for resource in files(package).iterdir() if resource.is_file())
22 changes: 0 additions & 22 deletions 22 Lib/importlib/resources/_legacy.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@
Resource = str


def deprecated(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
f"{func.__name__} is deprecated. Use files() instead. "
"Refer to https://importlib-resources.readthedocs.io"
"/en/latest/using.html#migrating-from-legacy for migration advice.",
DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)

return wrapper


def normalize_path(path: Any) -> str:
"""Normalize a path by ensuring it is a string.

Expand All @@ -39,19 +24,16 @@ def normalize_path(path: Any) -> str:
return file_name


@deprecated
def open_binary(package: Package, resource: Resource) -> BinaryIO:
"""Return a file-like object opened for binary reading of the resource."""
return (_common.files(package) / normalize_path(resource)).open('rb')


@deprecated
def read_binary(package: Package, resource: Resource) -> bytes:
"""Return the binary contents of the resource."""
return (_common.files(package) / normalize_path(resource)).read_bytes()


@deprecated
def open_text(
package: Package,
resource: Resource,
Expand All @@ -64,7 +46,6 @@ def open_text(
)


@deprecated
def read_text(
package: Package,
resource: Resource,
Expand All @@ -80,7 +61,6 @@ def read_text(
return fp.read()


@deprecated
def contents(package: Package) -> Iterable[str]:
"""Return an iterable of entries in `package`.

Expand All @@ -91,7 +71,6 @@ def contents(package: Package) -> Iterable[str]:
return [path.name for path in _common.files(package).iterdir()]


@deprecated
def is_resource(package: Package, name: str) -> bool:
"""True if `name` is a resource inside `package`.

Expand All @@ -104,7 +83,6 @@ def is_resource(package: Package, name: str) -> bool:
)


@deprecated
def path(
package: Package,
resource: Resource,
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2025-04-07-07-59-32.gh-issue-116608.-2nlIp.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
undeprecate functional API for ``importlib.resources``
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.