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
Provenance
- Commit
08a0d69- Tree
bf7bdf3- Author
Javier Domingo Cansino <javierdo1@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
97fde8b
5 files changed+35 added−28 removed
modified:src/click/_winconsole.py+1 added-1 removed
111 unmodified lines112 def __init__(self, handle):113 self.handle = handle114 115 def isatty(self):116- io.RawIOBase.isatty(self)116+ super().isatty()117 return True118 119 120 class _WindowsConsoleReader(_WindowsConsoleRawIOBase):188 unmodified linesmodified:src/click/core.py+21 added-15 removed
907 unmodified lines908 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 they220 unmodified lines1137 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_command16 unmodified lines1162 " optional arguments."1163 )1164 1165 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 rv1169 1170 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)1173 1174 def resultcallback(self, replace=False):1175 """Adds a result callback to the command. By default if a67 unmodified lines1243 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()1246 1247- rest = Command.parse_args(self, ctx, args)1247+ rest = super().parse_args(ctx, args)1248+1249 if self.chain:1250 ctx.protected_args = rest1251 ctx.args = []1252 elif rest:12 unmodified lines1265 # 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.")1272 1273 # Fetch args back out9 unmodified lines1283 # 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 lines1295 # 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)1300 1301 # 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 lines1366 :param commands: a dictionary of commands.1367 """1368 1369 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 {}1373 1374 def add_command(self, cmd, name=None):50 unmodified lines1425 provides all the commands for each of them.1426 """1427 1428 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 []1432 1433 def add_source(self, multi_cmd):329 unmodified lines1763 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)1768 1769 if prompt is True:1770 prompt_text = self.name.replace("_", " ").capitalize()1771 elif prompt is False:208 unmodified lines1980 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)1984 1985+ return super().get_default(ctx)1986+1987 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 processed17 unmodified lines2008 value_proc=lambda x: self.process_value(ctx, x),2009 )2010 2011 def resolve_envvar_value(self, ctx):2010- rv = Parameter.resolve_envvar_value(self, ctx)2012+ rv = super().resolve_envvar_value(ctx)2013+2014 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 lines2030 2031 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)2034 2035+ return super().full_process_value(ctx, value)2036 2037+2038 class 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 lines2050 if attrs.get("default") is not None:2051 required = False2052 else:2053 required = attrs.get("nargs", 1) > 02054+2050- Parameter.__init__(self, param_decls, required=required, **attrs)2055+ super().__init__(param_decls, required=required, **attrs)2056+2057 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 linesmodified:src/click/exceptions.py+8 added-9 removed
41 unmodified lines42 43 exit_code = 244 45 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 None49 50 def show(self, file=None):30 unmodified lines81 each item is quoted and separated.82 """83 84 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_hint88 89 def format_message(self):22 unmodified lines112 113 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_type118 119 def format_message(self):120 if self.param_hint is not None:37 unmodified lines158 159 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)162+163+ super().__init__(message, ctx)164 self.option_name = option_name165 self.possibilities = possibilities166 167 def format_message(self):17 unmodified lines185 :param option_name: the name of the option being used incorrectly.186 """187 188 def __init__(self, option_name, message, ctx=None):188- UsageError.__init__(self, message, ctx)189+ super().__init__(message, ctx)190 self.option_name = option_name191 192 193 class BadArgumentUsage(UsageError):3 unmodified lines197 198 .. versionadded:: 6.0199 """200 200- def __init__(self, message, ctx=None):201- UsageError.__init__(self, message, ctx)201 203-202 class FileError(ClickException):203 """Raised if a file cannot be opened."""204 205 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)209+210+ super().__init__(hint)211 self.ui_filename = ui_filename212 self.filename = filename213 214 def format_message(self):18 unmodified linesmodified:src/click/types.py+4 added-2 removed
276 unmodified lines277 self.max = max278 self.clamp = clamp279 280 def convert(self, value, param, ctx):281- rv = IntParamType.convert(self, value, param, ctx)281+ rv = super().convert(value, param, ctx)282+283 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 lines344 self.max = max345 self.clamp = clamp346 347 def convert(self, value, param, ctx):347- rv = FloatParamType.convert(self, value, param, ctx)348+ rv = super().convert(value, param, ctx)349+350 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 linesmodified:tests/test_commands.py+1 added-1 removed
131 unmodified lines132 pass133 134 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 = callback139 140 def parse_args(self, ctx, args):176 unmodified lines