From 97b4576f655c09e32d2cbcdcdbda72b1bf9f438a Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 26 May 2021 14:09:27 -0700 Subject: bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387) (#26389) Automerge-Triggered-By: GH:jaraco (cherry picked from commit f6fbdb90ee450ad693f7a7809035d0dc968f98b7) Co-authored-by: Jason R. Coombs Co-authored-by: Jason R. Coombs --- Lib/importlib/_common.py | 4 ++-- Lib/importlib/readers.py | 7 +++---- Lib/importlib/resources.py | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'Lib/importlib') diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py index ed509971ce..549fee379a 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 3e91c1cae6..41089c071d 100644 --- a/Lib/importlib/readers.py +++ b/Lib/importlib/readers.py @@ -94,16 +94,15 @@ class MultiplexedPath(abc.Traversable): __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 db0e0c0eef..8a98663ff8 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( -- cgit v1.2.1