From: Jason R. Coombs Date: Wed, 26 May 2021 18:49:06 +0000 (-0400) Subject: bpo-38693: importlib.metadata f-strings (GH-26383) X-Git-Tag: v3.11.0a1~1024 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6c815d2e34be5fdf6dbe773f0781691746d2289;p=thirdparty%2FPython%2Fcpython.git bpo-38693: importlib.metadata f-strings (GH-26383) Automerge-Triggered-By: GH:jaraco --- diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index 9637a828c522..94b83869a685 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -48,8 +48,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): @@ -386,7 +385,7 @@ class FileHash: self.mode, _, self.value = spec.partition('=') def __repr__(self): - return ''.format(self.mode, self.value) + return f'' class Distribution: @@ -570,13 +569,13 @@ class Distribution: """ 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 000000000000..2a568a4f469f --- /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.