[Python-checkins] bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387)
miss-islington
webhook-mailer at python.org
Wed May 26 16:16:22 EDT 2021
https://github.com/python/cpython/commit/f6fbdb90ee450ad693f7a7809035d0dc968f98b7
commit: f6fbdb90ee450ad693f7a7809035d0dc968f98b7
branch: main
author: Jason R. Coombs <jaraco at jaraco.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-05-26T13:16:11-07:00
summary:
bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387)
Automerge-Triggered-By: GH:jaraco
files:
A Misc/NEWS.d/next/Library/2021-05-26-14-50-06.bpo-38693.NkMacJ.rst
M Lib/importlib/_common.py
M Lib/importlib/readers.py
M Lib/importlib/resources.py
M Lib/test/test_importlib/test_reader.py
M Lib/test/test_importlib/test_resource.py
diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py
index ed509971ce718..549fee379a415 100644
--- a/Lib/importlib/_common.py
+++ b/Lib/importlib/_common.py
@@ -31,7 +31,7 @@ def normalize_path(path):
str_path = str(path)
parent, file_name = os.path.split(str_path)
if parent:
- raise ValueError('{!r} must be only a file name'.format(path))
+ raise ValueError(f'{path!r} must be only a file name')
return file_name
@@ -65,7 +65,7 @@ def get_package(package):
"""
resolved = resolve(package)
if wrap_spec(resolved).submodule_search_locations is None:
- raise TypeError('{!r} is not a package'.format(package))
+ raise TypeError(f'{package!r} is not a package')
return resolved
diff --git a/Lib/importlib/readers.py b/Lib/importlib/readers.py
index 3e91c1cae6758..41089c071d868 100644
--- a/Lib/importlib/readers.py
+++ b/Lib/importlib/readers.py
@@ -94,16 +94,15 @@ def joinpath(self, child):
__truediv__ = joinpath
def open(self, *args, **kwargs):
- raise FileNotFoundError('{} is not a file'.format(self))
+ raise FileNotFoundError(f'{self} is not a file')
@property
def name(self):
return self._paths[0].name
def __repr__(self):
- return 'MultiplexedPath({})'.format(
- ', '.join("'{}'".format(path) for path in self._paths)
- )
+ paths = ', '.join(f"'{path}'" for path in self._paths)
+ return f'MultiplexedPath({paths})'
class NamespaceReader(abc.TraversableResources):
diff --git a/Lib/importlib/resources.py b/Lib/importlib/resources.py
index db0e0c0eeff80..8a98663ff8e6d 100644
--- a/Lib/importlib/resources.py
+++ b/Lib/importlib/resources.py
@@ -68,9 +68,7 @@ def open_binary(package: Package, resource: Resource) -> BinaryIO:
if data is not None:
return BytesIO(data)
- raise FileNotFoundError(
- '{!r} resource not found in {!r}'.format(resource, spec.name)
- )
+ raise FileNotFoundError(f'{resource!r} resource not found in {spec.name!r}')
def open_text(
diff --git a/Lib/test/test_importlib/test_reader.py b/Lib/test/test_importlib/test_reader.py
index ed1f6be717b7e..9d20c976b8250 100644
--- a/Lib/test/test_importlib/test_reader.py
+++ b/Lib/test/test_importlib/test_reader.py
@@ -79,7 +79,7 @@ def test_join_path(self):
def test_repr(self):
self.assertEqual(
repr(MultiplexedPath(self.folder)),
- "MultiplexedPath('{}')".format(self.folder),
+ f"MultiplexedPath('{self.folder}')",
)
def test_name(self):
@@ -121,7 +121,7 @@ def test_files(self):
reader = NamespaceReader(namespacedata01.__spec__.submodule_search_locations)
root = os.path.abspath(os.path.join(__file__, '..', 'namespacedata01'))
self.assertIsInstance(reader.files(), MultiplexedPath)
- self.assertEqual(repr(reader.files()), "MultiplexedPath('{}')".format(root))
+ self.assertEqual(repr(reader.files()), f"MultiplexedPath('{root}')")
if __name__ == '__main__':
diff --git a/Lib/test/test_importlib/test_resource.py b/Lib/test/test_importlib/test_resource.py
index f8d861e9d4c20..003f7e95ad912 100644
--- a/Lib/test/test_importlib/test_resource.py
+++ b/Lib/test/test_importlib/test_resource.py
@@ -152,7 +152,7 @@ def setUp(self):
data_path = pathlib.Path(self.ZIP_MODULE.__file__)
data_dir = data_path.parent
self.source_zip_path = data_dir / 'ziptestdata.zip'
- self.zip_path = pathlib.Path('{}.zip'.format(uuid.uuid4())).absolute()
+ self.zip_path = pathlib.Path(f'{uuid.uuid4()}.zip').absolute()
self.zip_path.write_bytes(self.source_zip_path.read_bytes())
sys.path.append(str(self.zip_path))
self.data = import_module('ziptestdata')
diff --git a/Misc/NEWS.d/next/Library/2021-05-26-14-50-06.bpo-38693.NkMacJ.rst b/Misc/NEWS.d/next/Library/2021-05-26-14-50-06.bpo-38693.NkMacJ.rst
new file mode 100644
index 0000000000000..10d014b5da562
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-05-26-14-50-06.bpo-38693.NkMacJ.rst
@@ -0,0 +1 @@
+Prefer f-strings to ``.format`` in importlib.resources.
More information about the Python-checkins
mailing list