Skip to content

Commit ee94f7c

Browse files
committed
Merge branch 'main' into error-message-none-spec-module
2 parents a542188 + c6773a1 commit ee94f7c

File tree

19 files changed

+183
-253
lines changed

19 files changed

+183
-253
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,31 @@ jobs:
3434
# https://blog.jaraco.com/efficient-use-of-ci-resources/
3535
matrix:
3636
python:
37-
- "3.9"
37+
- "3.10"
3838
- "3.13"
3939
platform:
4040
- ubuntu-latest
4141
- macos-latest
4242
- windows-latest
4343
include:
44-
- python: "3.10"
45-
platform: ubuntu-latest
4644
- python: "3.11"
4745
platform: ubuntu-latest
4846
- python: "3.12"
4947
platform: ubuntu-latest
5048
- python: "3.14"
5149
platform: ubuntu-latest
50+
- python: "3.15"
51+
platform: ubuntu-latest
5252
- python: pypy3.10
5353
platform: ubuntu-latest
5454
runs-on: ${{ matrix.platform }}
55-
continue-on-error: ${{ matrix.python == '3.14' }}
55+
continue-on-error: ${{ matrix.python == '3.15' }}
5656
steps:
5757
- uses: actions/checkout@v4
5858
- name: Install build dependencies
5959
# Install dependencies for building packages on pre-release Pythons
6060
# jaraco/skeleton#161
61-
if: matrix.python == '3.14' && matrix.platform == 'ubuntu-latest'
61+
if: matrix.python == '3.15' && matrix.platform == 'ubuntu-latest'
6262
run: |
6363
sudo apt update
6464
sudo apt install -y libxml2-dev libxslt-dev

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.9.9
3+
rev: v0.12.0
44
hooks:
5-
- id: ruff
5+
- id: ruff-check
66
args: [--fix, --unsafe-fixes]
77
- id: ruff-format

NEWS.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
v7.0.0
2+
======
3+
4+
Deprecations and Removals
5+
-------------------------
6+
7+
- Remove compatibility shim for deprecated parameter *package* in
8+
:func:`importlib.resources.files`. Patch by Semyon Moroz. (#332)
9+
10+
111
v6.5.2
212
======
313

importlib_resources/_common.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,14 @@
77
import pathlib
88
import tempfile
99
import types
10-
import warnings
11-
from typing import Optional, Union, cast
10+
from typing import Optional, cast
1211

1312
from .abc import ResourceReader, Traversable
1413

15-
Package = Union[types.ModuleType, str]
14+
Package = types.ModuleType | str
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.

importlib_resources/abc.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
import itertools
33
import os
44
import pathlib
5+
from collections.abc import Iterable, Iterator
56
from typing import (
67
Any,
78
BinaryIO,
8-
Iterable,
9-
Iterator,
10-
NoReturn,
119
Literal,
10+
NoReturn,
1211
Optional,
1312
Protocol,
1413
Text,
1514
TextIO,
16-
Union,
1715
overload,
1816
runtime_checkable,
1917
)
2018

21-
StrPath = Union[str, os.PathLike[str]]
19+
StrPath = str | os.PathLike[str]
2220

2321
__all__ = ["ResourceReader", "Traversable", "TraversableResources"]
2422

@@ -151,9 +149,7 @@ def open(self, mode: Literal['r'] = 'r', *args: Any, **kwargs: Any) -> TextIO: .
151149
def open(self, mode: Literal['rb'], *args: Any, **kwargs: Any) -> BinaryIO: ...
152150

153151
@abc.abstractmethod
154-
def open(
155-
self, mode: str = 'r', *args: Any, **kwargs: Any
156-
) -> Union[TextIO, BinaryIO]:
152+
def open(self, mode: str = 'r', *args: Any, **kwargs: Any) -> TextIO | BinaryIO:
157153
"""
158154
mode may be 'r' or 'rb' to open as text or binary. Return a handle
159155
suitable for reading (same as pathlib.Path.open).

importlib_resources/simple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import abc
66
import io
77
import itertools
8-
from typing import BinaryIO, List
8+
from typing import BinaryIO
99

1010
from .abc import Traversable, TraversableResources
1111

@@ -24,14 +24,14 @@ def package(self) -> str:
2424
"""
2525

2626
@abc.abstractmethod
27-
def children(self) -> List['SimpleReader']:
27+
def children(self) -> list['SimpleReader']:
2828
"""
2929
Obtain an iterable of SimpleReader for available
3030
child containers (e.g. directories).
3131
"""
3232

3333
@abc.abstractmethod
34-
def resources(self) -> List[str]:
34+
def resources(self) -> list[str]:
3535
"""
3636
Obtain available named resources for this virtual package.
3737
"""

importlib_resources/tests/_path.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import functools
22
import pathlib
3-
from typing import Dict, Protocol, Union, runtime_checkable
3+
from typing import Protocol, Union, runtime_checkable
44

55
####
66
# from jaraco.path 3.7.1
@@ -12,7 +12,7 @@ class Symlink(str):
1212
"""
1313

1414

15-
FilesSpec = Dict[str, Union[str, bytes, Symlink, 'FilesSpec']]
15+
FilesSpec = dict[str, Union[str, bytes, Symlink, 'FilesSpec']]
1616

1717

1818
@runtime_checkable
@@ -28,13 +28,13 @@ def write_bytes(self, content): ... # pragma: no cover
2828
def symlink_to(self, target): ... # pragma: no cover
2929

3030

31-
def _ensure_tree_maker(obj: Union[str, TreeMaker]) -> TreeMaker:
31+
def _ensure_tree_maker(obj: str | TreeMaker) -> TreeMaker:
3232
return obj if isinstance(obj, TreeMaker) else pathlib.Path(obj) # type: ignore[return-value]
3333

3434

3535
def build(
3636
spec: FilesSpec,
37-
prefix: Union[str, TreeMaker] = pathlib.Path(), # type: ignore[assignment]
37+
prefix: str | TreeMaker = pathlib.Path(), # type: ignore[assignment]
3838
):
3939
"""
4040
Build a set of files/directories, as described by the spec.
@@ -66,7 +66,7 @@ def build(
6666

6767

6868
@functools.singledispatch
69-
def create(content: Union[str, bytes, FilesSpec], path):
69+
def create(content: str | bytes | FilesSpec, path):
7070
path.mkdir(exist_ok=True)
7171
build(content, prefix=path) # type: ignore[arg-type]
7272

importlib_resources/tests/test_compatibilty_files.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,46 @@ def files(self):
2525
return resources.files(self.package)
2626

2727
def test_spec_path_iter(self):
28-
self.assertEqual(
29-
sorted(path.name for path in self.files.iterdir()),
30-
['a', 'b', 'c'],
31-
)
28+
assert sorted(path.name for path in self.files.iterdir()) == ['a', 'b', 'c']
3229

3330
def test_child_path_iter(self):
34-
self.assertEqual(list((self.files / 'a').iterdir()), [])
31+
assert list((self.files / 'a').iterdir()) == []
3532

3633
def test_orphan_path_iter(self):
37-
self.assertEqual(list((self.files / 'a' / 'a').iterdir()), [])
38-
self.assertEqual(list((self.files / 'a' / 'a' / 'a').iterdir()), [])
34+
assert list((self.files / 'a' / 'a').iterdir()) == []
35+
assert list((self.files / 'a' / 'a' / 'a').iterdir()) == []
3936

4037
def test_spec_path_is(self):
41-
self.assertFalse(self.files.is_file())
42-
self.assertFalse(self.files.is_dir())
38+
assert not self.files.is_file()
39+
assert not self.files.is_dir()
4340

4441
def test_child_path_is(self):
45-
self.assertTrue((self.files / 'a').is_file())
46-
self.assertFalse((self.files / 'a').is_dir())
42+
assert (self.files / 'a').is_file()
43+
assert not (self.files / 'a').is_dir()
4744

4845
def test_orphan_path_is(self):
49-
self.assertFalse((self.files / 'a' / 'a').is_file())
50-
self.assertFalse((self.files / 'a' / 'a').is_dir())
51-
self.assertFalse((self.files / 'a' / 'a' / 'a').is_file())
52-
self.assertFalse((self.files / 'a' / 'a' / 'a').is_dir())
46+
assert not (self.files / 'a' / 'a').is_file()
47+
assert not (self.files / 'a' / 'a').is_dir()
48+
assert not (self.files / 'a' / 'a' / 'a').is_file()
49+
assert not (self.files / 'a' / 'a' / 'a').is_dir()
5350

5451
def test_spec_path_name(self):
55-
self.assertEqual(self.files.name, 'testingpackage')
52+
assert self.files.name == 'testingpackage'
5653

5754
def test_child_path_name(self):
58-
self.assertEqual((self.files / 'a').name, 'a')
55+
assert (self.files / 'a').name == 'a'
5956

6057
def test_orphan_path_name(self):
61-
self.assertEqual((self.files / 'a' / 'b').name, 'b')
62-
self.assertEqual((self.files / 'a' / 'b' / 'c').name, 'c')
58+
assert (self.files / 'a' / 'b').name == 'b'
59+
assert (self.files / 'a' / 'b' / 'c').name == 'c'
6360

6461
def test_spec_path_open(self):
65-
self.assertEqual(self.files.read_bytes(), b'Hello, world!')
66-
self.assertEqual(self.files.read_text(encoding='utf-8'), 'Hello, world!')
62+
assert self.files.read_bytes() == b'Hello, world!'
63+
assert self.files.read_text(encoding='utf-8') == 'Hello, world!'
6764

6865
def test_child_path_open(self):
69-
self.assertEqual((self.files / 'a').read_bytes(), b'Hello, world!')
70-
self.assertEqual(
71-
(self.files / 'a').read_text(encoding='utf-8'), 'Hello, world!'
72-
)
66+
assert (self.files / 'a').read_bytes() == b'Hello, world!'
67+
assert (self.files / 'a').read_text(encoding='utf-8') == 'Hello, world!'
7368

7469
def test_orphan_path_open(self):
7570
with self.assertRaises(FileNotFoundError):
@@ -87,7 +82,7 @@ def test_orphan_path_invalid(self):
8782

8883
def test_wrap_spec(self):
8984
spec = wrap_spec(self.package)
90-
self.assertIsInstance(spec.loader.get_resource_reader(None), CompatibilityFiles)
85+
assert isinstance(spec.loader.get_resource_reader(None), CompatibilityFiles)
9186

9287

9388
class CompatibilityFilesNoReaderTests(unittest.TestCase):
@@ -100,4 +95,4 @@ def files(self):
10095
return resources.files(self.package)
10196

10297
def test_spec_path_joinpath(self):
103-
self.assertIsInstance(self.files / 'a', CompatibilityFiles.OrphanPath)
98+
assert isinstance(self.files / 'a', CompatibilityFiles.OrphanPath)

importlib_resources/tests/test_files.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ def test_traversable(self):
3737
def test_joinpath_with_multiple_args(self):
3838
files = resources.files(self.data)
3939
binfile = files.joinpath('subdirectory', 'binary.file')
40-
self.assertTrue(binfile.is_file())
41-
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)
40+
assert binfile.is_file()
4941

5042

5143
class OpenDiskTests(FilesTests, util.DiskSetup, unittest.TestCase):

0 commit comments

Comments
 (0)