Skip to content
Myr

use super() consistently

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Javier Domingo Cansino · committed by David Lord · parent 97fde8b · Browse files · 5 files+35 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+35 added−28 removed

  • tests:+1 added−1 removed
  • other:+34 added−27 removed

5 files+35 added−28 removed

modified:src/click/_winconsole.py+1 added-1 removed
111 unmodified lines
112 def __init__(self, handle):113 self.handle = handle114115 def isatty(self):116 io.RawIOBase.isatty(self)116 super().isatty()117 return True118119120class _WindowsConsoleReader(_WindowsConsoleRawIOBase):
188 unmodified lines
modified:src/click/core.py+21 added-15 removed
907 unmodified lines
908 no_args_is_help=False,909 hidden=False,910 deprecated=False,911 ):912 BaseCommand.__init__(self, name, context_settings)912 super().__init__(name, context_settings)913 #: the callback to execute when the command fires. This might be914 #: `None` in which case nothing happens.915 self.callback = callback916 #: the list of parameters for this command in the order they
220 unmodified lines
1137 chain=False,1138 result_callback=None,1139 **attrs,1140 ):1141 Command.__init__(self, name, **attrs)1141 super().__init__(name, **attrs)1142 if no_args_is_help is None:1143 no_args_is_help = not invoke_without_command1144 self.no_args_is_help = no_args_is_help1145 self.invoke_without_command = invoke_without_command
16 unmodified lines
1162 " optional arguments."1163 )11641165 def collect_usage_pieces(self, ctx):1166 rv = Command.collect_usage_pieces(self, ctx)1166 rv = super().collect_usage_pieces(ctx)1167 rv.append(self.subcommand_metavar)1168 return rv11691170 def format_options(self, ctx, formatter):1171 Command.format_options(self, ctx, formatter)1171 super().format_options(ctx, formatter)1172 self.format_commands(ctx, formatter)11731174 def resultcallback(self, replace=False):1175 """Adds a result callback to the command. By default if a
67 unmodified lines
1243 if not args and self.no_args_is_help and not ctx.resilient_parsing:1244 echo(ctx.get_help(), color=ctx.color)1245 ctx.exit()12461247 rest = Command.parse_args(self, ctx, args)1247 rest = super().parse_args(ctx, args)12481249 if self.chain:1250 ctx.protected_args = rest1251 ctx.args = []1252 elif rest:
12 unmodified lines
1265 # No subcommand was invoked, so the result callback is1266 # invoked with None for regular groups, or an empty list1267 # for chained groups.1268 with ctx:1268 Command.invoke(self, ctx)1269 super().invoke(ctx)1270 return _process_result([] if self.chain else None)1271 ctx.fail("Missing command.")12721273 # Fetch args back out
9 unmodified lines
1283 # resources until the result processor has worked.1284 with ctx:1285 cmd_name, cmd, args = self.resolve_command(ctx, args)1286 ctx.invoked_subcommand = cmd_name1286 Command.invoke(self, ctx)1287 super().invoke(ctx)1288 sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)1289 with sub_ctx:1290 return _process_result(sub_ctx.command.invoke(sub_ctx))1291
3 unmodified lines
1295 # set to ``*`` to inform the command that subcommands are executed1296 # but nothing else.1297 with ctx:1298 ctx.invoked_subcommand = "*" if args else None1298 Command.invoke(self, ctx)1299 super().invoke(ctx)13001301 # Otherwise we make every single context and invoke them in a1302 # chain. In that case the return value to the result processor1303 # is the list of all invoked subcommand's results.
62 unmodified lines
1366 :param commands: a dictionary of commands.1367 """13681369 def __init__(self, name=None, commands=None, **attrs):1369 MultiCommand.__init__(self, name, **attrs)1370 super().__init__(name, **attrs)1371 #: the registered subcommands by their exported names.1372 self.commands = commands or {}13731374 def add_command(self, cmd, name=None):
50 unmodified lines
1425 provides all the commands for each of them.1426 """14271428 def __init__(self, name=None, sources=None, **attrs):1428 MultiCommand.__init__(self, name, **attrs)1429 super().__init__(name, **attrs)1430 #: The list of registered multi commands.1431 self.sources = sources or []14321433 def add_source(self, multi_cmd):
329 unmodified lines
1763 show_envvar=False,1764 **attrs,1765 ):1766 default_is_missing = attrs.get("default", _missing) is _missing1766 Parameter.__init__(self, param_decls, type=type, **attrs)1767 super().__init__(param_decls, type=type, **attrs)17681769 if prompt is True:1770 prompt_text = self.name.replace("_", " ").capitalize()1771 elif prompt is False:
208 unmodified lines
1980 for param in ctx.command.params:1981 if param.name == self.name and param.default:1982 return param.flag_value1983 return None1983 return Parameter.get_default(self, ctx)19841985 return super().get_default(ctx)19861987 def prompt_for_value(self, ctx):1988 """This is an alternative flow that can be activated in the full1989 value processing if a value does not exist. It will prompt the1990 user until a valid value exists and then returns the processed
17 unmodified lines
2008 value_proc=lambda x: self.process_value(ctx, x),2009 )20102011 def resolve_envvar_value(self, ctx):2010 rv = Parameter.resolve_envvar_value(self, ctx)2012 rv = super().resolve_envvar_value(ctx)20132014 if rv is not None:2015 return rv2016 if self.allow_from_autoenv and ctx.auto_envvar_prefix is not None:2017 envvar = f"{ctx.auto_envvar_prefix}_{self.name.upper()}"
12 unmodified lines
20302031 def full_process_value(self, ctx, value):2032 if value is None and self.prompt is not None and not ctx.resilient_parsing:2033 return self.prompt_for_value(ctx)2031 return Parameter.full_process_value(self, ctx, value)20342035 return super().full_process_value(ctx, value)203620372038class Argument(Parameter):2039 """Arguments are positional parameters to a command. They generally2040 provide fewer features than options but can have infinite ``nargs``2041 and are required by default.
8 unmodified lines
2050 if attrs.get("default") is not None:2051 required = False2052 else:2053 required = attrs.get("nargs", 1) > 020542050 Parameter.__init__(self, param_decls, required=required, **attrs)2055 super().__init__(param_decls, required=required, **attrs)20562057 if self.default is not None and self.nargs < 0:2058 raise TypeError(2059 "nargs=-1 in combination with a default value is not supported."2060 )
42 unmodified lines
modified:src/click/exceptions.py+8 added-9 removed
41 unmodified lines
4243 exit_code = 24445 def __init__(self, message, ctx=None):46 ClickException.__init__(self, message)46 super().__init__(message)47 self.ctx = ctx48 self.cmd = self.ctx.command if self.ctx else None4950 def show(self, file=None):
30 unmodified lines
81 each item is quoted and separated.82 """8384 def __init__(self, message, ctx=None, param=None, param_hint=None):85 UsageError.__init__(self, message, ctx)85 super().__init__(message, ctx)86 self.param = param87 self.param_hint = param_hint8889 def format_message(self):
22 unmodified lines
112113 def __init__(114 self, message=None, ctx=None, param=None, param_hint=None, param_type=None115 ):116 BadParameter.__init__(self, message, ctx, param, param_hint)116 super().__init__(message, ctx, param, param_hint)117 self.param_type = param_type118119 def format_message(self):120 if self.param_hint is not None:
37 unmodified lines
158159 def __init__(self, option_name, message=None, possibilities=None, ctx=None):160 if message is None:161 message = f"no such option: {option_name}"162 UsageError.__init__(self, message, ctx)162163 super().__init__(message, ctx)164 self.option_name = option_name165 self.possibilities = possibilities166167 def format_message(self):
17 unmodified lines
185 :param option_name: the name of the option being used incorrectly.186 """187188 def __init__(self, option_name, message, ctx=None):188 UsageError.__init__(self, message, ctx)189 super().__init__(message, ctx)190 self.option_name = option_name191192193class BadArgumentUsage(UsageError):
3 unmodified lines
197198 .. versionadded:: 6.0199 """200200 def __init__(self, message, ctx=None):201 UsageError.__init__(self, message, ctx)201203202class FileError(ClickException):203 """Raised if a file cannot be opened."""204205 def __init__(self, filename, hint=None):206 ui_filename = filename_to_ui(filename)207 if hint is None:208 hint = "unknown error"211 ClickException.__init__(self, hint)209210 super().__init__(hint)211 self.ui_filename = ui_filename212 self.filename = filename213214 def format_message(self):
18 unmodified lines
modified:src/click/types.py+4 added-2 removed
276 unmodified lines
277 self.max = max278 self.clamp = clamp279280 def convert(self, value, param, ctx):281 rv = IntParamType.convert(self, value, param, ctx)281 rv = super().convert(value, param, ctx)282283 if self.clamp:284 if self.min is not None and rv < self.min:285 return self.min286 if self.max is not None and rv > self.max:
57 unmodified lines
344 self.max = max345 self.clamp = clamp346347 def convert(self, value, param, ctx):347 rv = FloatParamType.convert(self, value, param, ctx)348 rv = super().convert(value, param, ctx)349350 if self.clamp:351 if self.min is not None and rv < self.min:352 return self.min353 if self.max is not None and rv > self.max:
375 unmodified lines
modified:tests/test_commands.py+1 added-1 removed
131 unmodified lines
132 pass133134 class OptParseCommand(click.BaseCommand):135 def __init__(self, name, parser, callback):136 click.BaseCommand.__init__(self, name)136 super().__init__(name)137 self.parser = parser138 self.callback = callback139140 def parse_args(self, ctx, args):
176 unmodified lines