Skip to content

Commit 9b2cf2e

Browse files
jaracoclaude
andcommitted
Repair the violations from Ruff 0.16's expanded defaults.
Ref jaraco/skeleton#210. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent db3a187 commit 9b2cf2e

10 files changed

Lines changed: 23 additions & 27 deletions

File tree

‎importlib_resources/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
from .abc import ResourceReader
2626

2727
__all__ = [
28-
'Package',
2928
'Anchor',
29+
'Package',
3030
'ResourceReader',
3131
'as_file',
32-
'files',
3332
'contents',
33+
'files',
3434
'is_resource',
3535
'open_binary',
3636
'open_text',

‎importlib_resources/_common.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
import pathlib
88
import tempfile
99
import types
10-
from typing import Optional, cast
10+
from typing import cast
1111

1212
from .abc import ResourceReader, Traversable
1313

1414
Package = types.ModuleType | str
1515
Anchor = Package
1616

1717

18-
def files(anchor: Optional[Anchor] = None) -> Traversable:
18+
def files(anchor: Anchor | None = None) -> Traversable:
1919
"""
2020
Get a Traversable resource for an anchor.
2121
"""
2222
return from_package(resolve(anchor))
2323

2424

25-
def get_resource_reader(package: types.ModuleType) -> Optional[ResourceReader]:
25+
def get_resource_reader(package: types.ModuleType) -> ResourceReader | None:
2626
"""
2727
Return the package's loader if it's a ResourceReader.
2828
"""
@@ -39,7 +39,7 @@ def get_resource_reader(package: types.ModuleType) -> Optional[ResourceReader]:
3939

4040

4141
@functools.singledispatch
42-
def resolve(cand: Optional[Anchor]) -> types.ModuleType:
42+
def resolve(cand: Anchor | None) -> types.ModuleType:
4343
return cast(types.ModuleType, cand)
4444

4545

‎importlib_resources/_itertools.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def only(iterable, default=None, too_long=None):
3030
pass
3131
else:
3232
msg = (
33-
'Expected exactly one item in iterable, but got {!r}, {!r}, '
34-
'and perhaps more.'.format(first_value, second_value)
33+
f'Expected exactly one item in iterable, but got {first_value!r}, '
34+
f'{second_value!r}, and perhaps more.'
3535
)
3636
raise too_long or ValueError(msg)
3737

‎importlib_resources/abc.py‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
BinaryIO,
99
Literal,
1010
NoReturn,
11-
Optional,
1211
Protocol,
13-
Text,
1412
TextIO,
1513
overload,
1614
runtime_checkable,
@@ -25,7 +23,7 @@ class ResourceReader(metaclass=abc.ABCMeta):
2523
"""Abstract base class for loaders to provide resource reading support."""
2624

2725
@abc.abstractmethod
28-
def open_resource(self, resource: Text) -> BinaryIO:
26+
def open_resource(self, resource: str) -> BinaryIO:
2927
"""Return an opened, file-like object for binary reading.
3028
3129
The 'resource' argument is expected to represent only a file name.
@@ -37,7 +35,7 @@ def open_resource(self, resource: Text) -> BinaryIO:
3735
raise FileNotFoundError
3836

3937
@abc.abstractmethod
40-
def resource_path(self, resource: Text) -> Text:
38+
def resource_path(self, resource: str) -> str:
4139
"""Return the file system path to the specified resource.
4240
4341
The 'resource' argument is expected to represent only a file name.
@@ -50,7 +48,7 @@ def resource_path(self, resource: Text) -> Text:
5048
raise FileNotFoundError
5149

5250
@abc.abstractmethod
53-
def is_resource(self, path: Text) -> bool:
51+
def is_resource(self, path: str) -> bool:
5452
"""Return True if the named 'path' is a resource.
5553
5654
Files are resources, directories are not.
@@ -90,9 +88,7 @@ def read_bytes(self) -> bytes:
9088
with self.open('rb') as strm:
9189
return strm.read()
9290

93-
def read_text(
94-
self, encoding: Optional[str] = None, errors: Optional[str] = None
95-
) -> str:
91+
def read_text(self, encoding: str | None = None, errors: str | None = None) -> str:
9692
"""
9793
Read contents of self as text
9894
"""

‎importlib_resources/compat/py39.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__all__ = ['ZipPath']
44

55

6-
if sys.version_info >= (3, 10):
6+
if sys.version_info >= (3, 10): # noqa: UP036 (shim retained; removal is a separate change)
77
from zipfile import Path as ZipPath
88
else:
99
from zipp import Path as ZipPath

‎importlib_resources/tests/test_contents.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class ContentsTests:
9-
expected = {
9+
expected = { # noqa: RUF012 (never mutated; overridden by subclasses)
1010
'__init__.py',
1111
'binary.file',
1212
'subdirectory',
@@ -30,7 +30,7 @@ class ContentsZipTests(ContentsTests, util.ZipSetup, unittest.TestCase):
3030
class ContentsNamespaceTests(ContentsTests, util.DiskSetup, unittest.TestCase):
3131
MODULE = 'namespacedata01'
3232

33-
expected = {
33+
expected = { # noqa: RUF012 (never mutated; overridden by subclasses)
3434
# no __init__ because of namespace design
3535
'binary.file',
3636
'subdirectory',

‎importlib_resources/tests/test_files.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def load_fixture(self, name):
8888

8989

9090
class ModulesFiles:
91-
spec = {
91+
spec = { # noqa: RUF012 (never mutated; overridden by subclasses)
9292
'mod.py': '',
9393
'res.txt': 'resources are the best',
9494
}
@@ -118,7 +118,7 @@ class ImplicitContextFiles:
118118
val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
119119
"""
120120
)
121-
spec = {
121+
spec = { # noqa: RUF012 (never mutated; overridden by subclasses)
122122
'somepkg': {
123123
'__init__.py': set_val,
124124
'submod.py': set_val,

‎importlib_resources/tests/test_functional.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_open_text(self):
123123
resources.open_text(self.anchor01)
124124
with self.assertRaises((OSError, resources.abc.TraversalError)):
125125
resources.open_text(self.anchor01, 'no-such-file')
126-
with resources.open_text(self.anchor01, 'utf-16.file') as f:
126+
with resources.open_text(self.anchor01, 'utf-16.file') as f: # noqa: SIM117 (kept in sync with CPython)
127127
with self.assertRaises(UnicodeDecodeError):
128128
f.read()
129129
with resources.open_text(
@@ -154,10 +154,10 @@ def test_open_binary(self):
154154
assert f.read() == b'a resource'
155155

156156
def test_path(self):
157-
with resources.path(self.anchor01, 'utf-8.file') as path:
157+
with resources.path(self.anchor01, 'utf-8.file') as path: # noqa: SIM117 (kept in sync with CPython)
158158
with open(str(path), encoding='utf-8') as f:
159159
assert f.read() == 'Hello, UTF-8 world!\n'
160-
with resources.path(self.anchor01) as path:
160+
with resources.path(self.anchor01) as path: # noqa: SIM117 (kept in sync with CPython)
161161
with open(os.path.join(path, 'utf-8.file'), encoding='utf-8') as f:
162162
assert f.read() == 'Hello, UTF-8 world!\n'
163163

@@ -223,7 +223,7 @@ def test_text_errors(self):
223223
resources.read_text,
224224
resources.open_text,
225225
):
226-
with self.subTest(func=func):
226+
with self.subTest(func=func): # noqa: SIM117 (kept in sync with CPython)
227227
# Multiple path arguments need explicit encoding argument.
228228
with self.assertRaises(TypeError):
229229
func(

‎importlib_resources/tests/util.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_useless_loader(self):
145145
'__init__.py': '',
146146
'binary.file': bytes(range(4)),
147147
'utf-16.file': '\ufeffHello, UTF-16 world!\n'.encode('utf-16-le'),
148-
'utf-8.file': 'Hello, UTF-8 world!\n'.encode('utf-8'),
148+
'utf-8.file': b'Hello, UTF-8 world!\n',
149149
'subdirectory': {
150150
'__init__.py': '',
151151
'binary.file': bytes(range(4, 8)),
@@ -160,7 +160,7 @@ def test_useless_loader(self):
160160
namespacedata01={
161161
'binary.file': bytes(range(4)),
162162
'utf-16.file': '\ufeffHello, UTF-16 world!\n'.encode('utf-16-le'),
163-
'utf-8.file': 'Hello, UTF-8 world!\n'.encode('utf-8'),
163+
'utf-8.file': b'Hello, UTF-8 world!\n',
164164
'subdirectory': {
165165
'binary.file': bytes(range(12, 16)),
166166
},

‎importlib_resources/tests/zip.py‎

100755100644
File mode changed.

0 commit comments

Comments
 (0)