Skip to content

Commit 243fdcb

Browse files
authored
gh-106531: Remove importlib.resources._legacy (#106532)
* gh-106531: Remove importlib.resources._legacy Syncs with importlib_resources 6.0. * Remove documentation for removed functionality.
1 parent 7c95345 commit 243fdcb

File tree

4 files changed

+3
-295
lines changed

4 files changed

+3
-295
lines changed

Doc/library/importlib.resources.rst

-156
Original file line numberDiff line numberDiff line change
@@ -94,159 +94,3 @@ for example, a package and its resources can be imported from a zip file using
9494
the file system is required.
9595

9696
.. versionadded:: 3.9
97-
98-
99-
Deprecated functions
100-
^^^^^^^^^^^^^^^^^^^^
101-
102-
An older, deprecated set of functions is still available, but is
103-
scheduled for removal in a future version of Python.
104-
The main drawback of these functions is that they do not support
105-
directories: they assume all resources are located directly within a *package*.
106-
107-
.. data:: Package
108-
109-
Whenever a function accepts a ``Package`` argument, you can pass in
110-
either a :class:`module object <types.ModuleType>` or a module name
111-
as a string. You can only pass module objects whose
112-
``__spec__.submodule_search_locations`` is not ``None``.
113-
114-
The ``Package`` type is defined as ``Union[str, ModuleType]``.
115-
116-
.. deprecated:: 3.12
117-
118-
119-
.. data:: Resource
120-
121-
For *resource* arguments of the functions below, you can pass in
122-
the name of a resource as a string or
123-
a :class:`path-like object <os.PathLike>`.
124-
125-
The ``Resource`` type is defined as ``Union[str, os.PathLike]``.
126-
127-
128-
.. function:: open_binary(package, resource)
129-
130-
Open for binary reading the *resource* within *package*.
131-
132-
*package* is either a name or a module object which conforms to the
133-
``Package`` requirements. *resource* is the name of the resource to open
134-
within *package*; it may not contain path separators and it may not have
135-
sub-resources (i.e. it cannot be a directory). This function returns a
136-
``typing.BinaryIO`` instance, a binary I/O stream open for reading.
137-
138-
.. deprecated:: 3.11
139-
140-
Calls to this function can be replaced by::
141-
142-
files(package).joinpath(resource).open('rb')
143-
144-
145-
.. function:: open_text(package, resource, encoding='utf-8', errors='strict')
146-
147-
Open for text reading the *resource* within *package*. By default, the
148-
resource is opened for reading as UTF-8.
149-
150-
*package* is either a name or a module object which conforms to the
151-
``Package`` requirements. *resource* is the name of the resource to open
152-
within *package*; it may not contain path separators and it may not have
153-
sub-resources (i.e. it cannot be a directory). *encoding* and *errors*
154-
have the same meaning as with built-in :func:`open`.
155-
156-
This function returns a ``typing.TextIO`` instance, a text I/O stream open
157-
for reading.
158-
159-
.. deprecated:: 3.11
160-
161-
Calls to this function can be replaced by::
162-
163-
files(package).joinpath(resource).open('r', encoding=encoding)
164-
165-
166-
.. function:: read_binary(package, resource)
167-
168-
Read and return the contents of the *resource* within *package* as
169-
``bytes``.
170-
171-
*package* is either a name or a module object which conforms to the
172-
``Package`` requirements. *resource* is the name of the resource to open
173-
within *package*; it may not contain path separators and it may not have
174-
sub-resources (i.e. it cannot be a directory). This function returns the
175-
contents of the resource as :class:`bytes`.
176-
177-
.. deprecated:: 3.11
178-
179-
Calls to this function can be replaced by::
180-
181-
files(package).joinpath(resource).read_bytes()
182-
183-
184-
.. function:: read_text(package, resource, encoding='utf-8', errors='strict')
185-
186-
Read and return the contents of *resource* within *package* as a ``str``.
187-
By default, the contents are read as strict UTF-8.
188-
189-
*package* is either a name or a module object which conforms to the
190-
``Package`` requirements. *resource* is the name of the resource to open
191-
within *package*; it may not contain path separators and it may not have
192-
sub-resources (i.e. it cannot be a directory). *encoding* and *errors*
193-
have the same meaning as with built-in :func:`open`. This function
194-
returns the contents of the resource as :class:`str`.
195-
196-
.. deprecated:: 3.11
197-
198-
Calls to this function can be replaced by::
199-
200-
files(package).joinpath(resource).read_text(encoding=encoding)
201-
202-
203-
.. function:: path(package, resource)
204-
205-
Return the path to the *resource* as an actual file system path. This
206-
function returns a context manager for use in a :keyword:`with` statement.
207-
The context manager provides a :class:`pathlib.Path` object.
208-
209-
Exiting the context manager cleans up any temporary file created when the
210-
resource needs to be extracted from e.g. a zip file.
211-
212-
*package* is either a name or a module object which conforms to the
213-
``Package`` requirements. *resource* is the name of the resource to open
214-
within *package*; it may not contain path separators and it may not have
215-
sub-resources (i.e. it cannot be a directory).
216-
217-
.. deprecated:: 3.11
218-
219-
Calls to this function can be replaced using :func:`as_file`::
220-
221-
as_file(files(package).joinpath(resource))
222-
223-
224-
.. function:: is_resource(package, name)
225-
226-
Return ``True`` if there is a resource named *name* in the package,
227-
otherwise ``False``.
228-
This function does not consider directories to be resources.
229-
*package* is either a name or a module object which conforms to the
230-
``Package`` requirements.
231-
232-
.. deprecated:: 3.11
233-
234-
Calls to this function can be replaced by::
235-
236-
files(package).joinpath(resource).is_file()
237-
238-
239-
.. function:: contents(package)
240-
241-
Return an iterable over the named items within the package. The iterable
242-
returns :class:`str` resources (e.g. files) and non-resources
243-
(e.g. directories). The iterable does not recurse into subdirectories.
244-
245-
*package* is either a name or a module object which conforms to the
246-
``Package`` requirements.
247-
248-
.. deprecated:: 3.11
249-
250-
Calls to this function can be replaced by::
251-
252-
(resource.name for resource in files(package).iterdir() if resource.is_file())

Lib/importlib/resources/__init__.py

-19
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,12 @@
66
Package,
77
)
88

9-
from ._legacy import (
10-
contents,
11-
open_binary,
12-
read_binary,
13-
open_text,
14-
read_text,
15-
is_resource,
16-
path,
17-
Resource,
18-
)
19-
209
from .abc import ResourceReader
2110

2211

2312
__all__ = [
2413
'Package',
25-
'Resource',
2614
'ResourceReader',
2715
'as_file',
28-
'contents',
2916
'files',
30-
'is_resource',
31-
'open_binary',
32-
'open_text',
33-
'path',
34-
'read_binary',
35-
'read_text',
3617
]

Lib/importlib/resources/_legacy.py

-120
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed ``_legacy`` and the names it provided from ``importlib.resources``:
2+
``Resource``, ``contents``, ``is_resource``, ``open_binary``, ``open_text``,
3+
``path``, ``read_binary``, and ``read_text``.

0 commit comments

Comments
 (0)