Skip to content

Commit eda0c15

Browse files
committed
bpo-33693: Prefer f-strings in importlib.metadata (importlib_metadata 4.2).
1 parent 06ac3a4 commit eda0c15

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
@@ -48,8 +48,7 @@ class PackageNotFoundError(ModuleNotFoundError):
4848
"""The package was not found."""
4949

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

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

388387
def __repr__(self):
389-
return '<FileHash mode: {} value: {}>'.format(self.mode, self.value)
388+
return f'<FileHash mode: {self.mode} value: {self.value}>'
390389

391390

392391
class Distribution:
@@ -570,13 +569,13 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
570569
"""
571570

572571
def make_condition(name):
573-
return name and 'extra == "{name}"'.format(name=name)
572+
return name and f'extra == "{name}"'
574573

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

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)