File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import pathlib
88import tempfile
99import types
10- import warnings
1110from typing import Optional , cast
1211
1312from .abc import ResourceReader , Traversable
1615Anchor = 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
5218def files (anchor : Optional [Anchor ] = None ) -> Traversable :
5319 """
5420 Get a Traversable resource for an anchor.
Original file line number Diff line number Diff line change @@ -39,14 +39,6 @@ def test_joinpath_with_multiple_args(self):
3939 binfile = files .joinpath ('subdirectory' , 'binary.file' )
4040 self .assertTrue (binfile .is_file ())
4141
42- def test_old_parameter (self ):
43- """
44- Files used to take a 'package' parameter. Make sure anyone
45- passing by name is still supported.
46- """
47- with suppress_known_deprecation ():
48- resources .files (package = self .data )
49-
5042
5143class OpenDiskTests (FilesTests , util .DiskSetup , unittest .TestCase ):
5244 pass
Original file line number Diff line number Diff line change 1+ Remove compatibility shim for deprecated parameter *package * in
2+ :func: `importlib.resources.files `. Patch by Semyon Moroz.
You can’t perform that action at this time.
0 commit comments