Skip to content

Commit bb8e934

Browse files
committed
Prefer f-strings
1 parent ecd1049 commit bb8e934

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

importlib_metadata/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class PackageNotFoundError(ModuleNotFoundError):
5252
"""The package was not found."""
5353

5454
def __str__(self):
55-
tmpl = "No package metadata was found for {self.name}"
56-
return tmpl.format(**locals())
55+
return f"No package metadata was found for {self.name}"
5756

5857
@property
5958
def name(self):
@@ -391,7 +390,7 @@ def __init__(self, spec):
391390
self.mode, _, self.value = spec.partition('=')
392391

393392
def __repr__(self):
394-
return '<FileHash mode: {} value: {}>'.format(self.mode, self.value)
393+
return f'<FileHash mode: {self.mode} value: {self.value}>'
395394

396395

397396
class Distribution:
@@ -575,13 +574,13 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
575574
"""
576575

577576
def make_condition(name):
578-
return name and 'extra == "{name}"'.format(name=name)
577+
return name and f'extra == "{name}"'
579578

580579
def parse_condition(section):
581580
section = section or ''
582581
extra, sep, markers = section.partition(':')
583582
if extra and markers:
584-
markers = '({markers})'.format(markers=markers)
583+
markers = f'({markers})'
585584
conditions = list(filter(None, [markers, make_condition(extra)]))
586585
return '; ' + ' and '.join(conditions) if conditions else ''
587586

importlib_metadata/_compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ class PyPy_repr:
7676
def __compat_repr__(self): # pragma: nocover
7777
def make_param(name):
7878
value = getattr(self, name)
79-
return '{name}={value!r}'.format(**locals())
79+
return f'{name}={value!r}'
8080

8181
params = ', '.join(map(make_param, self._fields))
82-
return 'EntryPoint({params})'.format(**locals())
82+
return f'EntryPoint({params})'
8383

8484
if affected: # pragma: nocover
8585
__repr__ = __compat_repr__

0 commit comments

Comments
 (0)