From 8dad4534993c0c902b7a2904905d92f33a7e6f27 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Fri, 22 Aug 2025 13:09:54 +0400 Subject: [PATCH] gh-138044: Remove deprecated parameter alias for `importlib.resources.files` --- Doc/library/importlib.resources.rst | 13 ++++--- Lib/importlib/resources/_common.py | 34 ------------------- .../test_importlib/resources/test_files.py | 8 ----- ...-08-22-12-48-14.gh-issue-138044.lEQULC.rst | 2 ++ 4 files changed, 8 insertions(+), 49 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-08-22-12-48-14.gh-issue-138044.lEQULC.rst diff --git a/Doc/library/importlib.resources.rst b/Doc/library/importlib.resources.rst index 7a11f4fe069004..8cb43f0625fc79 100644 --- a/Doc/library/importlib.resources.rst +++ b/Doc/library/importlib.resources.rst @@ -72,13 +72,12 @@ for example, a package and its resources can be imported from a zip file using .. versionadded:: 3.9 - .. versionchanged:: 3.12 - *package* parameter was renamed to *anchor*. *anchor* can now - be a non-package module and if omitted will default to the caller's - module. *package* is still accepted for compatibility but will raise - a :exc:`DeprecationWarning`. Consider passing the anchor positionally or - using ``importlib_resources >= 5.10`` for a compatible interface - on older Pythons. + .. deprecated-removed:: 3.12 3.15 + *package* parameter was renamed to *anchor*. *anchor* can now be a + non-package module and if omitted will default to the caller's module. + *package* is no longer accepted since Python 3.15. Consider passing the + anchor positionally or using ``importlib_resources >= 5.10`` for a + compatible interface on older Pythons. .. function:: as_file(traversable) diff --git a/Lib/importlib/resources/_common.py b/Lib/importlib/resources/_common.py index 4e9014c45a056e..d16ebe4520fbbf 100644 --- a/Lib/importlib/resources/_common.py +++ b/Lib/importlib/resources/_common.py @@ -6,7 +6,6 @@ import types import importlib import inspect -import warnings import itertools from typing import Union, Optional, cast @@ -16,39 +15,6 @@ Anchor = Package -def package_to_anchor(func): - """ - Replace 'package' parameter as 'anchor' and warn about the change. - - Other errors should fall through. - - >>> files('a', 'b') - Traceback (most recent call last): - TypeError: files() takes from 0 to 1 positional arguments but 2 were given - - Remove this compatibility in Python 3.14. - """ - undefined = object() - - @functools.wraps(func) - def wrapper(anchor=undefined, package=undefined): - if package is not undefined: - if anchor is not undefined: - return func(anchor, package) - warnings.warn( - "First parameter to files is renamed to 'anchor'", - DeprecationWarning, - stacklevel=2, - ) - return func(package) - elif anchor is undefined: - return func() - return func(anchor) - - return wrapper - - -@package_to_anchor def files(anchor: Optional[Anchor] = None) -> Traversable: """ Get a Traversable resource for an anchor. diff --git a/Lib/test/test_importlib/resources/test_files.py b/Lib/test/test_importlib/resources/test_files.py index 3ce44999f98ee5..c935b1e10ac87c 100644 --- a/Lib/test/test_importlib/resources/test_files.py +++ b/Lib/test/test_importlib/resources/test_files.py @@ -38,14 +38,6 @@ def test_joinpath_with_multiple_args(self): binfile = files.joinpath('subdirectory', 'binary.file') self.assertTrue(binfile.is_file()) - def test_old_parameter(self): - """ - Files used to take a 'package' parameter. Make sure anyone - passing by name is still supported. - """ - with suppress_known_deprecation(): - resources.files(package=self.data) - class OpenDiskTests(FilesTests, util.DiskSetup, unittest.TestCase): pass diff --git a/Misc/NEWS.d/next/Library/2025-08-22-12-48-14.gh-issue-138044.lEQULC.rst b/Misc/NEWS.d/next/Library/2025-08-22-12-48-14.gh-issue-138044.lEQULC.rst new file mode 100644 index 00000000000000..99ed3adef91a69 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-08-22-12-48-14.gh-issue-138044.lEQULC.rst @@ -0,0 +1,2 @@ +Remove compatibility shim for deprecated parameter *package* in +:func:`importlib.resources.files`. Patch by Semyon Moroz.