[Python-checkins] bpo-38693: importlib.metadata f-strings (GH-26383)

miss-islington webhook-mailer at python.org
Wed May 26 15:11:49 EDT 2021


https://github.com/python/cpython/commit/78a8428548445b501f5ebd6ff4647d93ffd8efd1
commit: 78a8428548445b501f5ebd6ff4647d93ffd8efd1
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-05-26T12:11:41-07:00
summary:

bpo-38693: importlib.metadata f-strings (GH-26383)


Automerge-Triggered-By: GH:jaraco
(cherry picked from commit e6c815d2e34be5fdf6dbe773f0781691746d2289)

Co-authored-by: Jason R. Coombs <jaraco at jaraco.com>

files:
A Misc/NEWS.d/next/Library/2021-05-26-13-34-37.bpo-33693.3okzdo.rst
M Lib/importlib/metadata/__init__.py

diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index e2f2e47f390bf..629f1858e5b79 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -47,8 +47,7 @@ class PackageNotFoundError(ModuleNotFoundError):
     """The package was not found."""
 
     def __str__(self):
-        tmpl = "No package metadata was found for {self.name}"
-        return tmpl.format(**locals())
+        return f"No package metadata was found for {self.name}"
 
     @property
     def name(self):
@@ -385,7 +384,7 @@ def __init__(self, spec):
         self.mode, _, self.value = spec.partition('=')
 
     def __repr__(self):
-        return '<FileHash mode: {} value: {}>'.format(self.mode, self.value)
+        return f'<FileHash mode: {self.mode} value: {self.value}>'
 
 
 class Distribution:
@@ -569,13 +568,13 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
         """
 
         def make_condition(name):
-            return name and 'extra == "{name}"'.format(name=name)
+            return name and f'extra == "{name}"'
 
         def parse_condition(section):
             section = section or ''
             extra, sep, markers = section.partition(':')
             if extra and markers:
-                markers = '({markers})'.format(markers=markers)
+                markers = f'({markers})'
             conditions = list(filter(None, [markers, make_condition(extra)]))
             return '; ' + ' and '.join(conditions) if conditions else ''
 
diff --git a/Misc/NEWS.d/next/Library/2021-05-26-13-34-37.bpo-33693.3okzdo.rst b/Misc/NEWS.d/next/Library/2021-05-26-13-34-37.bpo-33693.3okzdo.rst
new file mode 100644
index 0000000000000..2a568a4f469f8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-05-26-13-34-37.bpo-33693.3okzdo.rst
@@ -0,0 +1 @@
+Importlib.metadata now prefers f-strings to .format.



More information about the Python-checkins mailing list