Skip to content

Commit 8d17d79

Browse files
authored
gh-138044: Remove deprecated parameter alias for importlib.resources.files (#138059)
1 parent db53ca3 commit 8d17d79

File tree

4 files changed

+8
-49
lines changed

4 files changed

+8
-49
lines changed

Doc/library/importlib.resources.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ for example, a package and its resources can be imported from a zip file using
7272

7373
.. versionadded:: 3.9
7474

75-
.. versionchanged:: 3.12
76-
*package* parameter was renamed to *anchor*. *anchor* can now
77-
be a non-package module and if omitted will default to the caller's
78-
module. *package* is still accepted for compatibility but will raise
79-
a :exc:`DeprecationWarning`. Consider passing the anchor positionally or
80-
using ``importlib_resources >= 5.10`` for a compatible interface
81-
on older Pythons.
75+
.. deprecated-removed:: 3.12 3.15
76+
*package* parameter was renamed to *anchor*. *anchor* can now be a
77+
non-package module and if omitted will default to the caller's module.
78+
*package* is no longer accepted since Python 3.15. Consider passing the
79+
anchor positionally or using ``importlib_resources >= 5.10`` for a
80+
compatible interface on older Pythons.
8281

8382
.. function:: as_file(traversable)
8483

Lib/importlib/resources/_common.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import types
77
import importlib
88
import inspect
9-
import warnings
109
import itertools
1110

1211
from typing import Union, Optional, cast
@@ -16,39 +15,6 @@
1615
Anchor = Package
1716

1817

19-
def package_to_anchor(func):
20-
"""
21-
Replace 'package' parameter as 'anchor' and warn about the change.
22-
23-
Other errors should fall through.
24-
25-
>>> files('a', 'b')
26-
Traceback (most recent call last):
27-
TypeError: files() takes from 0 to 1 positional arguments but 2 were given
28-
29-
Remove this compatibility in Python 3.14.
30-
"""
31-
undefined = object()
32-
33-
@functools.wraps(func)
34-
def wrapper(anchor=undefined, package=undefined):
35-
if package is not undefined:
36-
if anchor is not undefined:
37-
return func(anchor, package)
38-
warnings.warn(
39-
"First parameter to files is renamed to 'anchor'",
40-
DeprecationWarning,
41-
stacklevel=2,
42-
)
43-
return func(package)
44-
elif anchor is undefined:
45-
return func()
46-
return func(anchor)
47-
48-
return wrapper
49-
50-
51-
@package_to_anchor
5218
def files(anchor: Optional[Anchor] = None) -> Traversable:
5319
"""
5420
Get a Traversable resource for an anchor.

Lib/test/test_importlib/resources/test_files.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ def test_joinpath_with_multiple_args(self):
3838
binfile = files.joinpath('subdirectory', 'binary.file')
3939
self.assertTrue(binfile.is_file())
4040

41-
def test_old_parameter(self):
42-
"""
43-
Files used to take a 'package' parameter. Make sure anyone
44-
passing by name is still supported.
45-
"""
46-
with suppress_known_deprecation():
47-
resources.files(package=self.data)
48-
4941

5042
class OpenDiskTests(FilesTests, util.DiskSetup, unittest.TestCase):
5143
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove compatibility shim for deprecated parameter *package* in
2+
:func:`importlib.resources.files`. Patch by Semyon Moroz.

0 commit comments

Comments
 (0)