summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-04-19 23:54:14 -0700
committerDavid Lord <davidism@gmail.com>2020-04-19 23:58:30 -0700
commit03dabdda8e48f0f87f13d24b9a2e65c1b0807635 (patch)
tree7f195251ffdb1399d0b289d4c0146e5c5e6027a2 /docs
parentd8bd5b1e6ececb9f8ee7cc05a94216b86ce80aed (diff)
downloadclick-03dabdda8e48f0f87f13d24b9a2e65c1b0807635.tar.gz
f-strings everywhere
Diffstat (limited to 'docs')
-rw-r--r--docs/advanced.rst14
-rw-r--r--docs/arguments.rst2
-rw-r--r--docs/bashcomplete.rst6
-rw-r--r--docs/commands.rst10
-rw-r--r--docs/documentation.rst4
-rw-r--r--docs/index.rst2
-rw-r--r--docs/options.rst40
-rw-r--r--docs/quickstart.rst2
-rw-r--r--docs/testing.rst6
-rw-r--r--docs/utils.rst11
10 files changed, 50 insertions, 47 deletions
diff --git a/docs/advanced.rst b/docs/advanced.rst
index 6278893..8003611 100644
--- a/docs/advanced.rst
+++ b/docs/advanced.rst
@@ -46,7 +46,7 @@ it would accept ``pus`` as an alias (so long as it was unique):
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])
- ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
+ ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
And it can then be used like this:
@@ -92,7 +92,7 @@ it's good to know that the system works this way.
@click.option('--url', callback=open_url)
def cli(url, fp=None):
if fp is not None:
- click.echo('%s: %s' % (url, fp.code))
+ click.echo(f"{url}: {fp.code}")
In this case the callback returns the URL unchanged but also passes a
second ``fp`` value to the callback. What's more recommended is to pass
@@ -116,7 +116,7 @@ the information in a wrapper however:
@click.option('--url', callback=open_url)
def cli(url):
if url is not None:
- click.echo('%s: %s' % (url.url, url.fp.code))
+ click.echo(f"{url.url}: {url.fp.code}")
Token Normalization
@@ -140,7 +140,7 @@ function that converts the token to lowercase:
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--name', default='Pete')
def cli(name):
- click.echo('Name: %s' % name)
+ click.echo(f"Name: {name}")
And how it works on the command line:
@@ -171,7 +171,7 @@ Example:
@cli.command()
@click.option('--count', default=1)
def test(count):
- click.echo('Count: %d' % count)
+ click.echo(f'Count: {count}')
@cli.command()
@click.option('--count', default=1)
@@ -300,7 +300,7 @@ In the end you end up with something like this:
"""A fake wrapper around Python's timeit."""
cmdline = ['echo', 'python', '-mtimeit'] + list(timeit_args)
if verbose:
- click.echo('Invoking: %s' % ' '.join(cmdline))
+ click.echo(f"Invoking: {' '.join(cmdline)}")
call(cmdline)
And what it looks like:
@@ -396,7 +396,7 @@ method can be used to find this out.
@click.pass_context
def cli(ctx, port):
source = ctx.get_parameter_source("port")
- click.echo("Port came from {}".format(source))
+ click.echo(f"Port came from {source}")
.. click:run::
diff --git a/docs/arguments.rst b/docs/arguments.rst
index 6ae3538..e5765c9 100644
--- a/docs/arguments.rst
+++ b/docs/arguments.rst
@@ -55,7 +55,7 @@ Example:
def copy(src, dst):
"""Move file SRC to DST."""
for fn in src:
- click.echo('move %s to folder %s' % (fn, dst))
+ click.echo(f"move {fn} to folder {dst}")
And what it looks like:
diff --git a/docs/bashcomplete.rst b/docs/bashcomplete.rst
index b2bb1b6..bc0ba7d 100644
--- a/docs/bashcomplete.rst
+++ b/docs/bashcomplete.rst
@@ -50,8 +50,8 @@ suggestions:
@click.command()
@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
def cmd1(envvar):
- click.echo('Environment variable: %s' % envvar)
- click.echo('Value: %s' % os.environ[envvar])
+ click.echo(f"Environment variable: {envvar}")
+ click.echo(f"Value: {os.environ[envvar]}")
Completion help strings
@@ -79,7 +79,7 @@ suggestions with help strings:
@click.command()
@click.argument("color", type=click.STRING, autocompletion=get_colors)
def cmd1(color):
- click.echo('Chosen color is %s' % color)
+ click.echo(f"Chosen color is {color}")
Activation
diff --git a/docs/commands.rst b/docs/commands.rst
index da26ac0..2bb9111 100644
--- a/docs/commands.rst
+++ b/docs/commands.rst
@@ -25,7 +25,7 @@ when an inner command runs:
@click.group()
@click.option('--debug/--no-debug', default=False)
def cli(debug):
- click.echo('Debug mode is %s' % ('on' if debug else 'off'))
+ click.echo(f"Debug mode is {'on' if debug else 'off'}")
@cli.command() # @cli, not @click!
def sync():
@@ -96,7 +96,7 @@ script like this:
@cli.command()
@click.pass_context
def sync(ctx):
- click.echo('Debug is %s' % (ctx.obj['DEBUG'] and 'on' or 'off'))
+ click.echo(f"Debug is {'on' if ctx.obj['DEBUG'] else 'off'}")
if __name__ == '__main__':
cli(obj={})
@@ -166,7 +166,7 @@ Example:
if ctx.invoked_subcommand is None:
click.echo('I was invoked without subcommand')
else:
- click.echo('I am about to invoke %s' % ctx.invoked_subcommand)
+ click.echo(f"I am about to invoke {ctx.invoked_subcommand}")
@cli.command()
def sync():
@@ -466,7 +466,7 @@ Example usage:
@cli.command()
@click.option('--port', default=8000)
def runserver(port):
- click.echo('Serving on http://127.0.0.1:%d/' % port)
+ click.echo(f"Serving on http://127.0.0.1:{port}/")
if __name__ == '__main__':
cli(default_map={
@@ -512,7 +512,7 @@ This example does the same as the previous example:
@cli.command()
@click.option('--port', default=8000)
def runserver(port):
- click.echo('Serving on http://127.0.0.1:%d/' % port)
+ click.echo(f"Serving on http://127.0.0.1:{port}/")
if __name__ == '__main__':
cli()
diff --git a/docs/documentation.rst b/docs/documentation.rst
index 982ad42..181c5b3 100644
--- a/docs/documentation.rst
+++ b/docs/documentation.rst
@@ -24,7 +24,7 @@ Simple example:
def hello(count, name):
"""This script prints hello NAME COUNT times."""
for x in range(count):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
And what it looks like:
@@ -173,7 +173,7 @@ desired. This can be customized at all levels:
def hello(count, name):
"""This script prints hello <name> <int> times."""
for x in range(count):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
Example:
diff --git a/docs/index.rst b/docs/index.rst
index 7fac849..683f1ef 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -36,7 +36,7 @@ What does it look like? Here is an example of a simple Click program:
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
if __name__ == '__main__':
hello()
diff --git a/docs/options.rst b/docs/options.rst
index 4942c8a..41653aa 100644
--- a/docs/options.rst
+++ b/docs/options.rst
@@ -85,7 +85,7 @@ simply pass in `required=True` as an argument to the decorator.
@click.option('--from', '-f', 'from_')
@click.option('--to', '-t')
def reserved_param_name(from_, to):
- click.echo('from %s to %s' % (from_, to))
+ click.echo(f"from {from_} to {to}")
And on the command line:
@@ -121,7 +121,8 @@ the ``nargs`` parameter. The values are then stored as a tuple.
@click.command()
@click.option('--pos', nargs=2, type=float)
def findme(pos):
- click.echo('%s / %s' % pos)
+ a, b = pos
+ click.echo(f"{a} / {b}")
And on the command line:
@@ -146,7 +147,8 @@ the tuple. For this you can directly specify a tuple as type:
@click.command()
@click.option('--item', type=(str, int))
def putitem(item):
- click.echo('name=%s id=%d' % item)
+ name, id = item
+ click.echo(f"name={name} id={id}")
And on the command line:
@@ -163,7 +165,8 @@ used. The above example is thus equivalent to this:
@click.command()
@click.option('--item', nargs=2, type=click.Tuple([str, int]))
def putitem(item):
- click.echo('name=%s id=%d' % item)
+ name, id = item
+ click.echo(f"name={name} id={id}")
.. _multiple-options:
@@ -212,7 +215,7 @@ for instance:
@click.command()
@click.option('-v', '--verbose', count=True)
def log(verbose):
- click.echo('Verbosity: %s' % verbose)
+ click.echo(f"Verbosity: {verbose}")
And on the command line:
@@ -281,7 +284,7 @@ can alternatively split the parameters through ``;`` instead:
@click.command()
@click.option('/debug;/no-debug')
def log(debug):
- click.echo('debug=%s' % debug)
+ click.echo(f"debug={debug}")
if __name__ == '__main__':
log()
@@ -402,7 +405,7 @@ Example:
@click.command()
@click.option('--name', prompt=True)
def hello(name):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
And what it looks like:
@@ -419,7 +422,7 @@ a different one:
@click.command()
@click.option('--name', prompt='Your name please')
def hello(name):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
What it looks like:
@@ -443,7 +446,7 @@ useful for password input:
@click.option('--password', prompt=True, hide_input=True,
confirmation_prompt=True)
def encrypt(password):
- click.echo('Encrypting password to %s' % password.encode('rot13'))
+ click.echo(f"Encrypting password to {password.encode('rot13')}")
What it looks like:
@@ -459,7 +462,7 @@ replaced with the :func:`password_option` decorator:
@click.command()
@click.password_option()
def encrypt(password):
- click.echo('Encrypting password to %s' % password.encode('rot13'))
+ click.echo(f"Encrypting password to {password.encode('rot13')}")
Dynamic Defaults for Prompts
----------------------------
@@ -625,7 +628,7 @@ Example usage:
@click.command()
@click.option('--username')
def greet(username):
- click.echo('Hello %s!' % username)
+ click.echo(f'Hello {username}!')
if __name__ == '__main__':
greet(auto_envvar_prefix='GREETER')
@@ -650,12 +653,12 @@ Example:
@click.group()
@click.option('--debug/--no-debug')
def cli(debug):
- click.echo('Debug mode is %s' % ('on' if debug else 'off'))
+ click.echo(f"Debug mode is {'on' if debug else 'off'}")
@cli.command()
@click.option('--username')
def greet(username):
- click.echo('Hello %s!' % username)
+ click.echo(f"Hello {username}!")
if __name__ == '__main__':
cli(auto_envvar_prefix='GREETER')
@@ -677,7 +680,7 @@ Example usage:
@click.command()
@click.option('--username', envvar='USERNAME')
def greet(username):
- click.echo('Hello %s!' % username)
+ click.echo(f"Hello {username}!")
if __name__ == '__main__':
greet()
@@ -726,7 +729,7 @@ And from the command line:
.. click:run::
import os
- invoke(perform, env={'PATHS': './foo/bar%s./test' % os.path.pathsep})
+ invoke(perform, env={"PATHS": f"./foo/bar{os.path.pathsep}./test"})
Other Prefix Characters
-----------------------
@@ -742,7 +745,7 @@ POSIX semantics. However in certain situations this can be useful:
@click.command()
@click.option('+w/-w')
def chmod(w):
- click.echo('writable=%s' % w)
+ click.echo(f"writable={w}")
if __name__ == '__main__':
chmod()
@@ -762,7 +765,7 @@ boolean flag you need to separate it with ``;`` instead of ``/``:
@click.command()
@click.option('/debug;/no-debug')
def log(debug):
- click.echo('debug=%s' % debug)
+ click.echo(f"debug={debug}")
if __name__ == '__main__':
log()
@@ -834,7 +837,8 @@ Example:
@click.command()
@click.option('--rolls', callback=validate_rolls, default='1d6')
def roll(rolls):
- click.echo('Rolling a %d-sided dice %d time(s)' % rolls)
+ sides, times = rolls
+ click.echo(f"Rolling a {sides}-sided dice {times} time(s)")
if __name__ == '__main__':
roll()
diff --git a/docs/quickstart.rst b/docs/quickstart.rst
index c8cb2d9..51f7f22 100644
--- a/docs/quickstart.rst
+++ b/docs/quickstart.rst
@@ -240,7 +240,7 @@ To add parameters, use the :func:`option` and :func:`argument` decorators:
@click.argument('name')
def hello(count, name):
for x in range(count):
- click.echo('Hello %s!' % name)
+ click.echo(f"Hello {name}!")
What it looks like:
diff --git a/docs/testing.rst b/docs/testing.rst
index 52a888d..57acaf2 100644
--- a/docs/testing.rst
+++ b/docs/testing.rst
@@ -30,7 +30,7 @@ data, exit code, and optional exception attached:
@click.command()
@click.argument('name')
def hello(name):
- click.echo('Hello %s!' % name)
+ click.echo(f'Hello {name}!')
.. code-block:: python
:caption: test_hello.py
@@ -54,7 +54,7 @@ For subcommand testing, a subcommand name must be specified in the `args` parame
@click.group()
@click.option('--debug/--no-debug', default=False)
def cli(debug):
- click.echo('Debug mode is %s' % ('on' if debug else 'off'))
+ click.echo(f"Debug mode is {'on' if debug else 'off'}")
@cli.command()
def sync():
@@ -126,7 +126,7 @@ stream (stdin). This is very useful for testing prompts, for instance:
@click.command()
@click.option('--foo', prompt=True)
def prompt(foo):
- click.echo('foo=%s' % foo)
+ click.echo(f"foo={foo}")
.. code-block:: python
:caption: test_prompt.py
diff --git a/docs/utils.rst b/docs/utils.rst
index 902e5fd..7dd8dbb 100644
--- a/docs/utils.rst
+++ b/docs/utils.rst
@@ -112,15 +112,14 @@ Example:
@click.command()
def less():
- click.echo_via_pager('\n'.join('Line %d' % idx
- for idx in range(200)))
+ click.echo_via_pager("\n".join(f"Line {idx}" for idx in range(200)))
If you want to use the pager for a lot of text, especially if generating everything in advance would take a lot of time, you can pass a generator (or generator function) instead of a string:
.. click:example::
def _generate_output():
for idx in range(50000):
- yield "Line %d\n" % idx
+ yield f"Line {idx}\n"
@click.command()
def less():
@@ -264,7 +263,7 @@ context of a full Unicode string.
Example::
- click.echo('Path: %s' % click.format_filename(b'foo.txt'))
+ click.echo(f"Path: {click.format_filename(b'foo.txt')}")
Standard Streams
@@ -349,7 +348,7 @@ Example usage::
rv = {}
for section in parser.sections():
for key, value in parser.items(section):
- rv['%s.%s' % (section, key)] = value
+ rv[f"{section}.{key}"] = value
return rv
@@ -396,7 +395,7 @@ loop. So code like this will render correctly::
with click.progressbar([1, 2, 3]) as bar:
for x in bar:
- print('sleep({})...'.format(x))
+ print(f"sleep({x})...")
time.sleep(x)
Another useful feature is to associate a label with the progress bar which