gh-138044: Remove deprecated parameter alias for importlib.resources.files (#138059)

This commit is contained in:
Semyon Moroz 2025-10-04 17:53:43 +04:00 committed by GitHub
parent db53ca30d7
commit 8d17d79299
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 49 deletions

View file

@ -72,13 +72,12 @@ for example, a package and its resources can be imported from a zip file using
.. versionadded:: 3.9 .. versionadded:: 3.9
.. versionchanged:: 3.12 .. deprecated-removed:: 3.12 3.15
*package* parameter was renamed to *anchor*. *anchor* can now *package* parameter was renamed to *anchor*. *anchor* can now be a
be a non-package module and if omitted will default to the caller's non-package module and if omitted will default to the caller's module.
module. *package* is still accepted for compatibility but will raise *package* is no longer accepted since Python 3.15. Consider passing the
a :exc:`DeprecationWarning`. Consider passing the anchor positionally or anchor positionally or using ``importlib_resources >= 5.10`` for a
using ``importlib_resources >= 5.10`` for a compatible interface compatible interface on older Pythons.
on older Pythons.
.. function:: as_file(traversable) .. function:: as_file(traversable)

View file

@ -6,7 +6,6 @@ import contextlib
import types import types
import importlib import importlib
import inspect import inspect
import warnings
import itertools import itertools
from typing import Union, Optional, cast from typing import Union, Optional, cast
@ -16,39 +15,6 @@ Package = Union[types.ModuleType, str]
Anchor = Package 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: def files(anchor: Optional[Anchor] = None) -> Traversable:
""" """
Get a Traversable resource for an anchor. Get a Traversable resource for an anchor.

View file

@ -38,14 +38,6 @@ class FilesTests:
binfile = files.joinpath('subdirectory', 'binary.file') binfile = files.joinpath('subdirectory', 'binary.file')
self.assertTrue(binfile.is_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): class OpenDiskTests(FilesTests, util.DiskSetup, unittest.TestCase):
pass pass

View file

@ -0,0 +1,2 @@
Remove compatibility shim for deprecated parameter *package* in
:func:`importlib.resources.files`. Patch by Semyon Moroz.