Skip to content
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
10 changes: 5 additions & 5 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ the program to the command line.
import fire

def hello(name):
return 'Hello {name}!'.format(name=name)
return f'Hello {name}!'

if __name__ == '__main__':
fire.Fire()
Expand All @@ -52,7 +52,7 @@ command line.
import fire

def hello(name):
return 'Hello {name}!'.format(name=name)
return f'Hello {name}!'

if __name__ == '__main__':
fire.Fire(hello)
Expand All @@ -76,7 +76,7 @@ We can alternatively write this program like this:
import fire

def hello(name):
return 'Hello {name}!'.format(name=name)
return f'Hello {name}!'

def main():
fire.Fire(hello)
Expand All @@ -93,7 +93,7 @@ then simply this:
import fire

def hello(name):
return 'Hello {name}!'.format(name=name)
return f'Hello {name}!'

def main():
fire.Fire(hello)
Expand All @@ -105,7 +105,7 @@ If you have a file `example.py` that doesn't even import fire:

```python
def hello(name):
return 'Hello {name}!'.format(name=name)
return f'Hello {name}!'
```

Then you can use it with Fire like this:
Expand Down
2 changes: 1 addition & 1 deletion examples/widget/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def whack(self, n=1):

def bang(self, noise='bang'):
"""Makes a loud noise."""
return '{noise} bang!'.format(noise=noise)
return f'{noise} bang!'


def main():
Expand Down
7 changes: 2 additions & 5 deletions fire/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ def _FishScript(name, commands, default_options=None):
)

return fish_source.format(
global_options=' '.join(
'"{option}"'.format(option=option)
for option in global_options
)
global_options=' '.join(f'"{option}"' for option in global_options)
)


Expand Down Expand Up @@ -385,7 +382,7 @@ def _CompletionsFromArgs(fn_args):
completions = []
for arg in fn_args:
arg = arg.replace('_', '-')
completions.append('--{arg}'.format(arg=arg))
completions.append(f'--{arg}')
return completions


Expand Down
3 changes: 1 addition & 2 deletions fire/completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def testCompletionBashScript(self):
self.assertIn('command', script)
self.assertIn('halt', script)

assert_template = '{command})'
for last_command in ['command', 'halt']:
self.assertIn(assert_template.format(command=last_command), script)
self.assertIn(f'{last_command})', script)

def testCompletionFishScript(self):
# A sanity check test to make sure the fish completion script satisfies
Expand Down
32 changes: 16 additions & 16 deletions fire/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ def Fire(component=None, command=None, name=None, serialize=None):
_DisplayError(component_trace)
raise FireExit(2, component_trace)
if component_trace.show_trace and component_trace.show_help:
output = ['Fire trace:\n{trace}\n'.format(trace=component_trace)]
output = [f'Fire trace:\n{component_trace}\n']
result = component_trace.GetResult()
help_text = helptext.HelpText(
result, trace=component_trace, verbose=component_trace.verbose)
output.append(help_text)
Display(output, out=sys.stderr)
raise FireExit(0, component_trace)
if component_trace.show_trace:
output = ['Fire trace:\n{trace}'.format(trace=component_trace)]
output = [f'Fire trace:\n{component_trace}']
Display(output, out=sys.stderr)
raise FireExit(0, component_trace)
if component_trace.show_help:
Expand Down Expand Up @@ -231,9 +231,9 @@ def _IsHelpShortcut(component_trace, remaining_args):

if show_help:
component_trace.show_help = True
command = '{cmd} -- --help'.format(cmd=component_trace.GetCommand())
print('INFO: Showing help with the command {cmd}.\n'.format(
cmd=shlex.quote(command)), file=sys.stderr)
command = f'{component_trace.GetCommand()} -- --help'
print(f'INFO: Showing help with the command {shlex.quote(command)}.\n',
file=sys.stderr)
return show_help


Expand Down Expand Up @@ -287,9 +287,9 @@ def _DisplayError(component_trace):
show_help = True

if show_help:
command = '{cmd} -- --help'.format(cmd=component_trace.GetCommand())
print('INFO: Showing help with the command {cmd}.\n'.format(
cmd=shlex.quote(command)), file=sys.stderr)
command = f'{component_trace.GetCommand()} -- --help'
print(f'INFO: Showing help with the command {shlex.quote(command)}.\n',
file=sys.stderr)
help_text = helptext.HelpText(result, trace=component_trace,
verbose=component_trace.verbose)
output.append(help_text)
Expand Down Expand Up @@ -327,14 +327,13 @@ def _DictAsString(result, verbose=False):
return '{}'

longest_key = max(len(str(key)) for key in result_visible.keys())
format_string = '{{key:{padding}s}} {{value}}'.format(padding=longest_key + 1)
format_string = f'{{key:{longest_key + 1}s}} {{value}}'

lines = []
for key, value in result.items():
if completion.MemberVisible(result, key, value, class_attrs=class_attrs,
verbose=verbose):
line = format_string.format(key=str(key) + ':',
value=_OneLineResult(value))
line = format_string.format(key=f'{key}:', value=_OneLineResult(value))
lines.append(line)
return '\n'.join(lines)

Expand All @@ -348,10 +347,10 @@ def _OneLineResult(result):
# TODO(dbieber): Show a small amount of usage information about the function
# or module if it fits cleanly on the line.
if inspect.isfunction(result):
return '<function {name}>'.format(name=result.__name__)
return f'<function {result.__name__}>'

if inspect.ismodule(result):
return '<module {name}>'.format(name=result.__name__)
return f'<module {result.__name__}>'

try:
# Don't force conversion to ascii.
Expand Down Expand Up @@ -890,9 +889,10 @@ def _ParseKeywordArgs(args, fn_spec):
if len(matching_fn_args) == 1:
keyword = matching_fn_args[0]
elif len(matching_fn_args) > 1:
raise FireError("The argument '{}' is ambiguous as it could "
"refer to any of the following arguments: {}".format(
argument, matching_fn_args))
raise FireError(
f"The argument '{argument}' is ambiguous as it could "
f"refer to any of the following arguments: {matching_fn_args}"
)

# Determine the value.
if not keyword:
Expand Down
Loading