diff options
| author | David Lord <davidism@gmail.com> | 2020-03-08 08:29:54 -0700 |
|---|---|---|
| committer | David Lord <davidism@gmail.com> | 2020-03-08 08:29:54 -0700 |
| commit | f8f02bfc63cb6e63b7a3373384758f7226553408 (patch) | |
| tree | f5ad9611416bccfe877664a2a119b06381e50005 /src/click | |
| parent | 30b82bfdebcc155acc1a63716ae8fd79a23f73e5 (diff) | |
| download | click-f8f02bfc63cb6e63b7a3373384758f7226553408.tar.gz | |
apply pyupgrade
Diffstat (limited to 'src/click')
| -rw-r--r-- | src/click/_bashcomplete.py | 2 | ||||
| -rw-r--r-- | src/click/_compat.py | 2 | ||||
| -rw-r--r-- | src/click/_termui_impl.py | 14 | ||||
| -rw-r--r-- | src/click/_winconsole.py | 4 | ||||
| -rw-r--r-- | src/click/core.py | 15 | ||||
| -rw-r--r-- | src/click/exceptions.py | 11 | ||||
| -rw-r--r-- | src/click/parser.py | 2 | ||||
| -rw-r--r-- | src/click/termui.py | 2 | ||||
| -rw-r--r-- | src/click/testing.py | 5 | ||||
| -rw-r--r-- | src/click/types.py | 26 | ||||
| -rw-r--r-- | src/click/utils.py | 2 |
11 files changed, 47 insertions, 38 deletions
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 |
