Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.10] bpo-38693: importlib.metadata f-strings (GH-26383) #26386

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 ''

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Importlib.metadata now prefers f-strings to .format.