diff options
author | Gregory P. Smith <greg@krypto.org> | 2022-10-07 01:27:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 01:27:51 (GMT) |
commit | 27369ef56ffed8ab68abc201a52b259a065ed8d7 (patch) | |
tree | 1048143cf501070cc318dbbffd70729bcc74341e /Lib/importlib/__init__.py | |
parent | fa2d43e5184f5eaf3391844ec2400342a1b2ead4 (diff) | |
download | cpython-27369ef56ffed8ab68abc201a52b259a065ed8d7.zip cpython-27369ef56ffed8ab68abc201a52b259a065ed8d7.tar.gz cpython-27369ef56ffed8ab68abc201a52b259a065ed8d7.tar.bz2 |
gh-82874: Convert remaining importlib format uses to f-str. (#98005)
f-yes
Diffstat (limited to 'Lib/importlib/__init__.py')
-rw-r--r-- | Lib/importlib/__init__.py | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index ce61883..21d9dee 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -84,13 +84,13 @@ def find_loader(name, path=None): try: loader = sys.modules[name].__loader__ if loader is None: - raise ValueError('{}.__loader__ is None'.format(name)) + raise ValueError(f'{name}.__loader__ is None') else: return loader except KeyError: pass except AttributeError: - raise ValueError('{}.__loader__ is not set'.format(name)) from None + raise ValueError(f'{name}.__loader__ is not set') from None spec = _bootstrap._find_spec(name, path) # We won't worry about malformed specs (missing attributes). @@ -98,8 +98,7 @@ def find_loader(name, path=None): return None if spec.loader is None: if spec.submodule_search_locations is None: - raise ImportError('spec for {} missing loader'.format(name), - name=name) + raise ImportError(f'spec for {name} missing loader', name=name) raise ImportError('namespace packages do not have loaders', name=name) return spec.loader @@ -116,9 +115,8 @@ def import_module(name, package=None): level = 0 if name.startswith('.'): if not package: - msg = ("the 'package' argument is required to perform a relative " - "import for {!r}") - raise TypeError(msg.format(name)) + raise TypeError("the 'package' argument is required to perform a " + f"relative import for {name!r}") for character in name: if character != '.': break @@ -144,8 +142,7 @@ def reload(module): raise TypeError("reload() argument must be a module") if sys.modules.get(name) is not module: - msg = "module {} not in sys.modules" - raise ImportError(msg.format(name), name=name) + raise ImportError(f"module {name} not in sys.modules", name=name) if name in _RELOADING: return _RELOADING[name] _RELOADING[name] = module @@ -155,8 +152,7 @@ def reload(module): try: parent = sys.modules[parent_name] except KeyError: - msg = "parent {!r} not in sys.modules" - raise ImportError(msg.format(parent_name), + raise ImportError(f"parent {parent_name!r} not in sys.modules", name=parent_name) from None else: pkgpath = parent.__path__ |