Skip to content

Commit 78a8428

Browse files
bpo-38693: importlib.metadata f-strings (GH-26383)
Automerge-Triggered-By: GH:jaraco (cherry picked from commit e6c815d) Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 1261941 commit 78a8428

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Lib/importlib/metadata/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class PackageNotFoundError(ModuleNotFoundError):
4747
"""The package was not found."""
4848

4949
def __str__(self):
50-
tmpl = "No package metadata was found for {self.name}"
51-
return tmpl.format(**locals())
50+
return f"No package metadata was found for {self.name}"
5251

5352
@property
5453
def name(self):
@@ -385,7 +384,7 @@ def __init__(self, spec):
385384
self.mode, _, self.value = spec.partition('=')
386385

387386
def __repr__(self):
388-
return '<FileHash mode: {} value: {}>'.format(self.mode, self.value)
387+
return f'<FileHash mode: {self.mode} value: {self.value}>'
389388

390389

391390
class Distribution:
@@ -569,13 +568,13 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
569568
"""
570569

571570
def make_condition(name):
572-
return name and 'extra == "{name}"'.format(name=name)
571+
return name and f'extra == "{name}"'
573572

574573
def parse_condition(section):
575574
section = section or ''
576575
extra, sep, markers = section.partition(':')
577576
if extra and markers:
578-
markers = '({markers})'.format(markers=markers)
577+
markers = f'({markers})'
579578
conditions = list(filter(None, [markers, make_condition(extra)]))
580579
return '; ' + ' and '.join(conditions) if conditions else ''
581580

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Importlib.metadata now prefers f-strings to .format.

0 commit comments

Comments
 (0)