https://github.com/python/cpython/commit/3fc57f86b12ad9ccd2cd6aa1303f185314246d60 commit: 3fc57f86b12ad9ccd2cd6aa1303f185314246d60 branch: 3.12 author: Thomas Grainger <tagr...@gmail.com> committer: Yhg1s <tho...@python.org> date: 2025-04-08T10:36:29+02:00 summary:
[3.12] gh-116608: undeprecate functional importlib.resources API (#132206) Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> files: A Misc/NEWS.d/next/Library/2025-04-07-07-59-32.gh-issue-116608.-2nlIp.rst M Doc/library/importlib.resources.rst M Lib/importlib/resources/_legacy.py diff --git a/Doc/library/importlib.resources.rst b/Doc/library/importlib.resources.rst index 6a35b882b766a3..1873ea7e1fb1a0 100644 --- a/Doc/library/importlib.resources.rst +++ b/Doc/library/importlib.resources.rst @@ -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*. @@ -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 @@ -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') @@ -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) @@ -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') @@ -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) @@ -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) @@ -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) @@ -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()) diff --git a/Lib/importlib/resources/_legacy.py b/Lib/importlib/resources/_legacy.py index b1ea8105dad6e2..a3ee4a6287c94b 100644 --- a/Lib/importlib/resources/_legacy.py +++ b/Lib/importlib/resources/_legacy.py @@ -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. @@ -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, @@ -64,7 +46,6 @@ def open_text( ) -@deprecated def read_text( package: Package, resource: Resource, @@ -80,7 +61,6 @@ def read_text( return fp.read() -@deprecated def contents(package: Package) -> Iterable[str]: """Return an iterable of entries in `package`. @@ -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`. @@ -104,7 +83,6 @@ def is_resource(package: Package, name: str) -> bool: ) -@deprecated def path( package: Package, resource: Resource, diff --git a/Misc/NEWS.d/next/Library/2025-04-07-07-59-32.gh-issue-116608.-2nlIp.rst b/Misc/NEWS.d/next/Library/2025-04-07-07-59-32.gh-issue-116608.-2nlIp.rst new file mode 100644 index 00000000000000..ac616de2da03a3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-04-07-07-59-32.gh-issue-116608.-2nlIp.rst @@ -0,0 +1 @@ +undeprecate functional API for ``importlib.resources`` _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com