summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-03-08 08:29:54 -0700
committerDavid Lord <davidism@gmail.com>2020-03-08 08:29:54 -0700
commitf8f02bfc63cb6e63b7a3373384758f7226553408 (patch)
treef5ad9611416bccfe877664a2a119b06381e50005
parent30b82bfdebcc155acc1a63716ae8fd79a23f73e5 (diff)
downloadclick-f8f02bfc63cb6e63b7a3373384758f7226553408.tar.gz
apply pyupgrade
-rw-r--r--examples/aliases/aliases.py2
-rw-r--r--examples/imagepipe/imagepipe.py14
-rw-r--r--examples/naval/naval.py8
-rw-r--r--examples/repo/repo.py8
-rw-r--r--src/click/_bashcomplete.py2
-rw-r--r--src/click/_compat.py2
-rw-r--r--src/click/_termui_impl.py14
-rw-r--r--src/click/_winconsole.py4
-rw-r--r--src/click/core.py15
-rw-r--r--src/click/exceptions.py11
-rw-r--r--src/click/parser.py2
-rw-r--r--src/click/termui.py2
-rw-r--r--src/click/testing.py5
-rw-r--r--src/click/types.py26
-rw-r--r--src/click/utils.py2
-rw-r--r--tests/test_imports.py46
-rw-r--r--tests/test_options.py4
-rw-r--r--tests/test_termui.py2
18 files changed, 89 insertions, 80 deletions
diff --git a/examples/aliases/aliases.py b/examples/aliases/aliases.py
index 8456a1b..1ebad50 100644
--- a/examples/aliases/aliases.py
+++ b/examples/aliases/aliases.py
@@ -139,4 +139,4 @@ def alias(config, alias_, cmd, config_file):
"""Adds an alias to the specified configuration file."""
config.add_alias(alias_, cmd)
config.write_config(config_file)
- click.echo("Added %s as alias for %s" % (alias_, cmd))
+ click.echo("Added {} as alias for {}".format(alias_, cmd))
diff --git a/examples/imagepipe/imagepipe.py b/examples/imagepipe/imagepipe.py
index 2cde2f6..5e34405 100644
--- a/examples/imagepipe/imagepipe.py
+++ b/examples/imagepipe/imagepipe.py
@@ -97,7 +97,7 @@ def open_cmd(images):
img = Image.open(image)
yield img
except Exception as e:
- click.echo('Could not open image "%s": %s' % (image, e), err=True)
+ click.echo('Could not open image "{}": {}'.format(image, e), err=True)
@cli.command("save")
@@ -114,10 +114,12 @@ def save_cmd(images, filename):
for idx, image in enumerate(images):
try:
fn = filename % (idx + 1)
- click.echo('Saving "%s" as "%s"' % (image.filename, fn))
+ click.echo('Saving "{}" as "{}"'.format(image.filename, fn))
yield image.save(fn)
except Exception as e:
- click.echo('Could not save image "%s": %s' % (image.filename, e), err=True)
+ click.echo(
+ 'Could not save image "{}": {}'.format(image.filename, e), err=True
+ )
@cli.command("display")
@@ -203,7 +205,7 @@ def transpose_cmd(images, rotate, flip):
image = copy_filename(image.transpose(mode), image)
if flip is not None:
mode, direction = flip
- click.echo('Flip "%s" %s' % (image.filename, direction))
+ click.echo('Flip "{}" {}'.format(image.filename, direction))
image = copy_filename(image.transpose(mode), image)
yield image
@@ -257,7 +259,7 @@ def emboss_cmd(images):
def sharpen_cmd(images, factor):
"""Sharpens an image."""
for image in images:
- click.echo('Sharpen "%s" by %f' % (image.filename, factor))
+ click.echo('Sharpen "{}" by {:f}'.format(image.filename, factor))
enhancer = ImageEnhance.Sharpness(image)
yield copy_filename(enhancer.enhance(max(1.0, factor)), image)
@@ -279,7 +281,7 @@ def paste_cmd(images, left, right):
yield image
return
- click.echo('Paste "%s" on "%s"' % (to_paste.filename, image.filename))
+ click.echo('Paste "{}" on "{}"'.format(to_paste.filename, image.filename))
mask = None
if to_paste.mode == "RGBA" or "transparency" in to_paste.info:
mask = to_paste
diff --git a/examples/naval/naval.py b/examples/naval/naval.py
index cf9e00c..a77dea8 100644
--- a/examples/naval/naval.py
+++ b/examples/naval/naval.py
@@ -31,7 +31,7 @@ def ship_new(name):
@click.option("--speed", metavar="KN", default=10, help="Speed in knots.")
def ship_move(ship, x, y, speed):
"""Moves SHIP to the new location X,Y."""
- click.echo("Moving ship %s to %s,%s with speed %s" % (ship, x, y, speed))
+ click.echo("Moving ship {} to {},{} with speed {}".format(ship, x, y, speed))
@ship.command("shoot")
@@ -40,7 +40,7 @@ def ship_move(ship, x, y, speed):
@click.argument("y", type=float)
def ship_shoot(ship, x, y):
"""Makes SHIP fire to X,Y."""
- click.echo("Ship %s fires to %s,%s" % (ship, x, y))
+ click.echo("Ship {} fires to {},{}".format(ship, x, y))
@cli.group("mine")
@@ -61,7 +61,7 @@ def mine():
@click.option("ty", "--drifting", flag_value="drifting", help="Drifting mine.")
def mine_set(x, y, ty):
"""Sets a mine at a specific coordinate."""
- click.echo("Set %s mine at %s,%s" % (ty, x, y))
+ click.echo("Set {} mine at {},{}".format(ty, x, y))
@mine.command("remove")
@@ -69,4 +69,4 @@ def mine_set(x, y, ty):
@click.argument("y", type=float)
def mine_remove(x, y):
"""Removes a mine at a specific coordinate."""
- click.echo("Removed mine at %s,%s" % (x, y))
+ click.echo("Removed mine at {},{}".format(x, y))
diff --git a/examples/repo/repo.py b/examples/repo/repo.py
index b9bf2f0..470296b 100644
--- a/examples/repo/repo.py
+++ b/examples/repo/repo.py
@@ -14,7 +14,7 @@ class Repo(object):
def set_config(self, key, value):
self.config[key] = value
if self.verbose:
- click.echo(" config[%s] = %s" % (key, value), file=sys.stderr)
+ click.echo(" config[{}] = {}".format(key, value), file=sys.stderr)
def __repr__(self):
return "<Repo %r>" % self.home
@@ -78,7 +78,7 @@ def clone(repo, src, dest, shallow, rev):
"""
if dest is None:
dest = posixpath.split(src)[-1] or "."
- click.echo("Cloning repo %s to %s" % (src, os.path.abspath(dest)))
+ click.echo("Cloning repo {} to {}".format(src, os.path.abspath(dest)))
repo.home = dest
if shallow:
click.echo("Making shallow checkout")
@@ -147,7 +147,7 @@ def commit(repo, files, message):
return
else:
msg = "\n".join(message)
- click.echo("Files to be committed: %s" % (files,))
+ click.echo("Files to be committed: {}".format(files))
click.echo("Commit message:\n" + msg)
@@ -163,4 +163,4 @@ def copy(repo, src, dst, force):
files from SRC to DST.
"""
for fn in src:
- click.echo("Copy from %s -> %s" % (fn, dst))
+ click.echo("Copy from {} -> {}".format(fn, dst))
diff --git a/src/click/_bashcomplete.py b/src/click/_bashcomplete.py
index 815eb02..3113808 100644
--- a/src/click/_bashcomplete.py
+++ b/src/click/_bashcomplete.py
@@ -349,7 +349,7 @@ def do_complete_fish(cli, prog_name):
for item in get_choices(cli, prog_name, args, incomplete):
if item[1]:
- echo("%(arg)s\t%(desc)s" % {"arg": item[0], "desc": item[1]})
+ echo("{arg}\t{desc}".format(arg=item[0], desc=item[1]))
else:
echo(item[0])
diff --git a/src/click/_compat.py b/src/click/_compat.py
index f7b1a8d..38ab8c0 100644
--- a/src/click/_compat.py
+++ b/src/click/_compat.py
@@ -565,7 +565,7 @@ def open_stream(filename, mode="r", encoding=None, errors="strict", atomic=False
while True:
tmp_filename = os.path.join(
os.path.dirname(filename),
- ".__atomic-write%08x" % (random.randrange(1 << 32),),
+ ".__atomic-write{:08x}".format(random.randrange(1 << 32)),
)
try:
fd = os.open(tmp_filename, flags, 0o666 if perm is None else perm)
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
index 784c64b..28a0d9c 100644
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -416,7 +416,7 @@ def _tempfilepager(generator, cmd, color):
with open_stream(filename, "wb")[0] as f:
f.write(text.encode(encoding))
try:
- os.system("%s %s" % (shlex_quote(cmd), shlex_quote(filename)))
+ os.system("{} {}".format(shlex_quote(cmd), shlex_quote(filename)))
finally:
os.unlink(filename)
@@ -461,7 +461,7 @@ class Editor(object):
environ = None
try:
c = subprocess.Popen(
- "%s %s" % (shlex_quote(editor), shlex_quote(filename)),
+ "{} {}".format(shlex_quote(editor), shlex_quote(filename)),
env=environ,
shell=True,
)
@@ -469,7 +469,7 @@ class Editor(object):
if exit_code != 0:
raise ClickException("%s: Editing failed!" % editor)
except OSError as e:
- raise ClickException("%s: Editing failed: %s" % (editor, e))
+ raise ClickException("{}: Editing failed: {}".format(editor, e))
def edit(self, text):
import tempfile
@@ -534,16 +534,16 @@ def open_url(url, wait=False, locate=False):
elif WIN:
if locate:
url = _unquote_file(url)
- args = "explorer /select,%s" % (shlex_quote(url),)
+ args = "explorer /select,{}".format(shlex_quote(url))
else:
- args = 'start %s "" %s' % ("/WAIT" if wait else "", shlex_quote(url))
+ args = 'start {} "" {}'.format("/WAIT" if wait else "", shlex_quote(url))
return os.system(args)
elif CYGWIN:
if locate:
url = _unquote_file(url)
- args = "cygstart %s" % (shlex_quote(os.path.dirname(url)),)
+ args = "cygstart {}".format(shlex_quote(os.path.dirname(url)))
else:
- args = "cygstart %s %s" % ("-w" if wait else "", shlex_quote(url))
+ args = "cygstart {} {}".format("-w" if wait else "", shlex_quote(url))
return os.system(args)
try:
diff --git a/src/click/_winconsole.py b/src/click/_winconsole.py
index ca43502..7b5be34 100644
--- a/src/click/_winconsole.py
+++ b/src/click/_winconsole.py
@@ -223,7 +223,9 @@ class ConsoleStream(object):
return self.buffer.isatty()
def __repr__(self):
- return "<ConsoleStream name=%r encoding=%r>" % (self.name, self.encoding,)
+ return "<ConsoleStream name={!r} encoding={!r}>".format(
+ self.name, self.encoding
+ )
class WindowsChunkedWriter(object):
diff --git a/src/click/core.py b/src/click/core.py
index ce60781..3537e59 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -379,9 +379,8 @@ class Context(object):
and parent.auto_envvar_prefix is not None
and self.info_name is not None
):
- auto_envvar_prefix = "%s_%s" % (
- parent.auto_envvar_prefix,
- self.info_name.upper(),
+ auto_envvar_prefix = "{}_{}".format(
+ parent.auto_envvar_prefix, self.info_name.upper(),
)
else:
auto_envvar_prefix = auto_envvar_prefix.upper()
@@ -676,7 +675,7 @@ class BaseCommand(object):
self.context_settings = context_settings
def __repr__(self):
- return "<%s %s>" % (self.__class__.__name__, self.name)
+ return "<{} {}>".format(self.__class__.__name__, self.name)
def get_usage(self, ctx):
raise NotImplementedError("Base commands cannot get usage")
@@ -1510,7 +1509,7 @@ class Parameter(object):
self.autocompletion = autocompletion
def __repr__(self):
- return "<%s %s>" % (self.__class__.__name__, self.name)
+ return "<{} {}>".format(self.__class__.__name__, self.name)
@property
def human_readable_name(self):
@@ -1883,7 +1882,7 @@ class Option(Parameter):
envvar = self.envvar
if envvar is None:
if self.allow_from_autoenv and ctx.auto_envvar_prefix is not None:
- envvar = "%s_%s" % (ctx.auto_envvar_prefix, self.name.upper())
+ envvar = "{}_{}".format(ctx.auto_envvar_prefix, self.name.upper())
if envvar is not None:
extra.append(
"env var: %s"
@@ -1907,7 +1906,7 @@ class Option(Parameter):
if self.required:
extra.append("required")
if extra:
- help = "%s[%s]" % (help and help + " " or "", "; ".join(extra))
+ help = "{}[{}]".format(help and help + " " or "", "; ".join(extra))
return ((any_prefix_is_slash and "; " or " / ").join(rv), help)
@@ -1952,7 +1951,7 @@ class Option(Parameter):
if rv is not None:
return rv
if self.allow_from_autoenv and ctx.auto_envvar_prefix is not None:
- envvar = "%s_%s" % (ctx.auto_envvar_prefix, self.name.upper())
+ envvar = "{}_{}".format(ctx.auto_envvar_prefix, self.name.upper())
return os.environ.get(envvar)
def value_from_envvar(self, ctx):
diff --git a/src/click/exceptions.py b/src/click/exceptions.py
index 2e2199b..5f5bf58 100644
--- a/src/click/exceptions.py
+++ b/src/click/exceptions.py
@@ -64,9 +64,8 @@ class UsageError(ClickException):
color = None
hint = ""
if self.cmd is not None and self.cmd.get_help_option(self.ctx) is not None:
- hint = 'Try "%s %s" for help.\n' % (
- self.ctx.command_path,
- self.ctx.help_option_names[0],
+ hint = 'Try "{} {}" for help.\n'.format(
+ self.ctx.command_path, self.ctx.help_option_names[0],
)
if self.ctx is not None:
color = self.ctx.color
@@ -106,7 +105,7 @@ class BadParameter(UsageError):
return "Invalid value: %s" % self.message
param_hint = _join_param_hints(param_hint)
- return "Invalid value for %s: %s" % (param_hint, self.message)
+ return "Invalid value for {}: {}".format(param_hint, self.message)
class MissingParameter(BadParameter):
@@ -149,7 +148,7 @@ class MissingParameter(BadParameter):
else:
msg = msg_extra
- return "Missing %s%s%s%s" % (
+ return "Missing {}{}{}{}".format(
param_type,
param_hint and " %s" % param_hint or "",
msg and ". " or ".",
@@ -234,7 +233,7 @@ class FileError(ClickException):
self.filename = filename
def format_message(self):
- return "Could not open file %s: %s" % (self.ui_filename, self.message)
+ return "Could not open file {}: {}".format(self.ui_filename, self.message)
class Abort(RuntimeError):
diff --git a/src/click/parser.py b/src/click/parser.py
index 16a41eb..b493ed4 100644
--- a/src/click/parser.py
+++ b/src/click/parser.py
@@ -225,7 +225,7 @@ class OptionParser(object):
self.ignore_unknown_options = ctx.ignore_unknown_options
self._short_opt = {}
self._long_opt = {}
- self._opt_prefixes = set(["-", "--"])
+ self._opt_prefixes = {"-", "--"}
self._args = []
def add_option(self, opts, dest, action=None, nargs=1, const=None, obj=None):
diff --git a/src/click/termui.py b/src/click/termui.py
index d5239e7..c39569f 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -61,7 +61,7 @@ def _build_prompt(
if type is not None and show_choices and isinstance(type, Choice):
prompt += " (" + ", ".join(map(str, type.choices)) + ")"
if default is not None and show_default:
- prompt = "%s [%s]" % (prompt, _format_default(default))
+ prompt = "{} [{}]".format(prompt, _format_default(default))
return prompt + suffix
diff --git a/src/click/testing.py b/src/click/testing.py
index 8131a7a..c5d1450 100644
--- a/src/click/testing.py
+++ b/src/click/testing.py
@@ -108,9 +108,8 @@ class Result(object):
)
def __repr__(self):
- return "<%s %s>" % (
- type(self).__name__,
- self.exception and repr(self.exception) or "okay",
+ return "<{} {}>".format(
+ type(self).__name__, self.exception and repr(self.exception) or "okay",
)
diff --git a/src/click/types.py b/src/click/types.py
index 0987190..8f4b9d2 100644
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -194,7 +194,9 @@ class Choice(ParamType):
return normed_choices[normed_value]
self.fail(
- "invalid choice: %s. (choose from %s)" % (value, ", ".join(self.choices)),
+ "invalid choice: {}. (choose from {})".format(
+ value, ", ".join(self.choices)
+ ),
param,
ctx,
)
@@ -299,7 +301,9 @@ class IntRange(IntParamType):
):
if self.min is None:
self.fail(
- "%s is bigger than the maximum valid value %s." % (rv, self.max),
+ "{} is bigger than the maximum valid value {}.".format(
+ rv, self.max
+ ),
param,
ctx,
)
@@ -320,7 +324,7 @@ class IntRange(IntParamType):
return rv
def __repr__(self):
- return "IntRange(%r, %r)" % (self.min, self.max)
+ return "IntRange({!r}, {!r})".format(self.min, self.max)
class FloatParamType(ParamType):
@@ -367,7 +371,9 @@ class FloatRange(FloatParamType):
):
if self.min is None:
self.fail(
- "%s is bigger than the maximum valid value %s." % (rv, self.max),
+ "{} is bigger than the maximum valid value {}.".format(
+ rv, self.max
+ ),
param,
ctx,
)
@@ -388,7 +394,7 @@ class FloatRange(FloatParamType):
return rv
def __repr__(self):
- return "FloatRange(%r, %r)" % (self.min, self.max)
+ return "FloatRange({!r}, {!r})".format(self.min, self.max)
class BoolParamType(ParamType):
@@ -597,20 +603,24 @@ class Path(ParamType):
if not self.exists:
return self.coerce_path_result(rv)
self.fail(
- '%s "%s" does not exist.' % (self.path_type, filename_to_ui(value)),
+ '{} "{}" does not exist.'.format(
+ self.path_type, filename_to_ui(value)
+ ),
param,
ctx,
)
if not self.file_okay and stat.S_ISREG(st.st_mode):
self.fail(
- '%s "%s" is a file.' % (self.path_type, filename_to_ui(value)),
+ '{} "{}" is a file.'.format(self.path_type, filename_to_ui(value)),
param,
ctx,
)
if not self.dir_okay and stat.S_ISDIR(st.st_mode):
self.fail(
- '%s "%s" is a directory.' % (self.path_type, filename_to_ui(value)),
+ '{} "{}" is a directory.'.format(
+ self.path_type, filename_to_ui(value)
+ ),
param,
ctx,
)
diff --git a/src/click/utils.py b/src/click/utils.py
index 4e97d84..58517b3 100644
--- a/src/click/utils.py
+++ b/src/click/utils.py
@@ -113,7 +113,7 @@ class LazyFile(object):
def __repr__(self):
if self._f is not None:
return repr(self._f)
- return "<unopened file %r %s>" % (self.name, self.mode)
+ return "<unopened file {!r} {}>".format(self.name, self.mode)
def open(self):
"""Opens the file if it's not yet open. This call might fail with
diff --git a/tests/test_imports.py b/tests/test_imports.py
index 9d52811..b99d453 100644
--- a/tests/test_imports.py
+++ b/tests/test_imports.py
@@ -29,30 +29,28 @@ import json
click.echo(json.dumps(rv))
"""
-ALLOWED_IMPORTS = set(
- [
- "weakref",
- "os",
- "struct",
- "collections",
- "sys",
- "contextlib",
- "functools",
- "stat",
- "re",
- "codecs",
- "inspect",
- "itertools",
- "io",
- "threading",
- "colorama",
- "errno",
- "fcntl",
- "datetime",
- "pipes",
- "shlex",
- ]
-)
+ALLOWED_IMPORTS = {
+ "weakref",
+ "os",
+ "struct",
+ "collections",
+ "sys",
+ "contextlib",
+ "functools",
+ "stat",
+ "re",
+ "codecs",
+ "inspect",
+ "itertools",
+ "io",
+ "threading",
+ "colorama",
+ "errno",
+ "fcntl",
+ "datetime",
+ "pipes",
+ "shlex",
+}
if WIN:
ALLOWED_IMPORTS.update(["ctypes", "ctypes.wintypes", "msvcrt", "time", "zlib"])
diff --git a/tests/test_options.py b/tests/test_options.py
index 0cdb064..3974803 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -13,7 +13,7 @@ def test_prefixes(runner):
@click.option("++foo", is_flag=True, help="das foo")
@click.option("--bar", is_flag=True, help="das bar")
def cli(foo, bar):
- click.echo("foo=%s bar=%s" % (foo, bar))
+ click.echo("foo={} bar={}".format(foo, bar))
result = runner.invoke(cli, ["++foo", "--bar"])
assert not result.exception
@@ -90,7 +90,7 @@ def test_unknown_options(runner, unknown_flag):
result = runner.invoke(cli, [unknown_flag])
assert result.exception
- assert "no such option: {0}".format(unknown_flag) in result.output
+ assert "no such option: {}".format(unknown_flag) in result.output
def test_multiple_required(runner):
diff --git a/tests/test_termui.py b/tests/test_termui.py
index 4e33f41..99a6a47 100644
--- a/tests/test_termui.py
+++ b/tests/test_termui.py
@@ -123,7 +123,7 @@ def test_progressbar_format_pos(runner, pos, length):
with _create_progress(length, length_known=length != 0, pos=pos) as progress:
result = progress.format_pos()
if progress.length_known:
- assert result == "%s/%s" % (pos, length)
+ assert result == "{}/{}".format(pos, length)
else:
assert result == str(pos)