Issue 9694: Use the term “option” instead of “optional argument” diff -r 55e5be11264e Doc/howto/argparse.rst --- a/Doc/howto/argparse.rst Mon Dec 15 17:19:27 2014 -0800 +++ b/Doc/howto/argparse.rst Tue Dec 16 05:17:45 2014 +0000 @@ -59,7 +59,7 @@ * Now, say we want to change behaviour of the program. In our example, we display more info for each file instead of just showing the file names. - The ``-l`` in that case is known as an optional argument. + The ``-l`` in that case is known as an option. * That's a snippet of the help text. It's very useful in that you can come across a program you have never used before, and can figure out @@ -83,7 +83,7 @@ $ python3 prog.py --help usage: prog.py [-h] - optional arguments: + options: -h, --help show this help message and exit $ python3 prog.py --verbose usage: prog.py [-h] @@ -106,7 +106,7 @@ also for free. -Introducing Positional arguments +Introducing positional arguments ================================ An example:: @@ -130,7 +130,7 @@ positional arguments: echo - optional arguments: + options: -h, --help show this help message and exit $ python3 prog.py foo foo @@ -141,7 +141,7 @@ which command-line options the program is willing to accept. In this case, I've named it ``echo`` so that it's in line with its function. -* Calling our program now requires us to specify an option. +* Calling our program now requires us to specify an argument. * The :meth:`parse_args` method actually returns some data from the options specified, in this case, ``echo``. @@ -172,7 +172,7 @@ positional arguments: echo echo the string you use here - optional arguments: + options: -h, --help show this help message and exit Now, how about doing something even more useful:: @@ -193,8 +193,8 @@ print(args.square**2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' -That didn't go so well. That's because :mod:`argparse` treats the options we -give it as strings, unless we tell it otherwise. So, let's tell +That didn't go so well. That's because :mod:`argparse` treats the +arguments we give it as strings, unless we tell it otherwise. So, let's tell :mod:`argparse` to treat that input as an integer:: import argparse @@ -218,11 +218,11 @@ before proceeding. -Introducing Optional arguments +Introducing options ============================== So far we, have been playing with positional arguments. Let us -have a look on how to add optional ones:: +have a look on how to add options:: import argparse parser = argparse.ArgumentParser() @@ -241,7 +241,7 @@ $ python3 prog.py --help usage: prog.py [-h] [--verbosity VERBOSITY] - optional arguments: + options: -h, --help show this help message and exit --verbosity VERBOSITY increase output verbosity @@ -254,7 +254,7 @@ * The program is written so as to display something when ``--verbosity`` is specified and display nothing when not. -* To show that the option is actually optional, there is no error when running +* To show that the option is optional, there is no error when running the program without it. Note that by default, if an optional argument isn't used, the relevant variable, in this case :attr:`args.verbosity`, is given ``None`` as a value, which is the reason it fails the truth @@ -289,7 +289,7 @@ $ python3 prog.py --help usage: prog.py [-h] [--verbose] - optional arguments: + options: -h, --help show this help message and exit --verbose increase output verbosity @@ -332,14 +332,14 @@ $ python3 prog.py --help usage: prog.py [-h] [-v] - optional arguments: + options: -h, --help show this help message and exit -v, --verbose increase output verbosity Note that the new ability is also reflected in the help text. -Combining Positional and Optional arguments +Combining positional arguments and options =========================================== Our program keeps growing in complexity:: @@ -440,7 +440,7 @@ positional arguments: square display a square of a given number - optional arguments: + options: -h, --help show this help message and exit -v {0,1,2}, --verbosity {0,1,2} increase output verbosity @@ -468,7 +468,7 @@ print(answer) We have introduced another action, "count", -to count the number of occurrences of a specific optional arguments: +to count the number of occurrences of a specific option: .. code-block:: sh @@ -489,7 +489,7 @@ positional arguments: square display a square of a given number - optional arguments: + options: -h, --help show this help message and exit -v, --verbosity increase output verbosity $ python3 prog.py 4 -vvv @@ -625,7 +625,7 @@ x the base y the exponent - optional arguments: + options: -h, --help show this help message and exit -v, --verbosity $ python3 prog.py 4 2 -v @@ -749,7 +749,7 @@ x the base y the exponent - optional arguments: + options: -h, --help show this help message and exit -v, --verbose -q, --quiet diff -r 55e5be11264e Doc/library/argparse.rst --- a/Doc/library/argparse.rst Mon Dec 15 17:19:27 2014 -0800 +++ b/Doc/library/argparse.rst Tue Dec 16 05:17:45 2014 +0000 @@ -54,7 +54,7 @@ positional arguments: N an integer for the accumulator - optional arguments: + options: -h, --help show this help message and exit --sum sum the integers (default: find the max) @@ -155,8 +155,7 @@ * formatter_class_ - A class for customizing the help output - * prefix_chars_ - The set of characters that prefix optional arguments - (default: '-') + * prefix_chars_ - The set of characters that prefix options (default: '-') * fromfile_prefix_chars_ - The set of characters that prefix files from which additional arguments should be read (default: ``None``) @@ -164,7 +163,7 @@ * argument_default_ - The global default value for arguments (default: ``None``) - * conflict_handler_ - The strategy for resolving conflicting optionals + * conflict_handler_ - The strategy for resolving conflicting options (usually unnecessary) * add_help_ - Add a -h/--help option to the parser (default: ``True``) @@ -192,14 +191,14 @@ $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help $ cd .. $ python subdir\myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help @@ -210,7 +209,7 @@ >>> parser.print_help() usage: myprogram [-h] - optional arguments: + options: -h, --help show this help message and exit Note that the program name, whether determined from ``sys.argv[0]`` or from the @@ -224,7 +223,7 @@ >>> parser.print_help() usage: myprogram [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo of the myprogram program @@ -244,7 +243,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo [FOO] foo help @@ -259,7 +258,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo [FOO] foo help @@ -282,7 +281,7 @@ A foo that bars - optional arguments: + options: -h, --help show this help message and exit By default, the description will be line-wrapped so that it fits within the @@ -304,7 +303,7 @@ A foo that bars - optional arguments: + options: -h, --help show this help message and exit And that's how you'd foo a bar @@ -321,7 +320,7 @@ repeating the definitions of these arguments, a single parser with all the shared arguments and passed to ``parents=`` argument to :class:`ArgumentParser` can be used. The ``parents=`` argument takes a list of :class:`ArgumentParser` -objects, collects all the positional and optional actions from them, and adds +objects, collects all the positional and option actions from them, and adds these actions to the :class:`ArgumentParser` object being constructed:: >>> parent_parser = argparse.ArgumentParser(add_help=False) @@ -378,7 +377,7 @@ this description was indented weird but that is okay - optional arguments: + options: -h, --help show this help message and exit likewise for this epilog whose whitespace will be cleaned up and whose words @@ -407,7 +406,7 @@ exactly the way I want it - optional arguments: + options: -h, --help show this help message and exit :class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text, @@ -427,7 +426,7 @@ positional arguments: bar BAR! (default: [1, 2, 3]) - optional arguments: + options: -h, --help show this help message and exit --foo FOO FOO! (default: 42) @@ -446,7 +445,7 @@ positional arguments: float - optional arguments: + options: -h, --help show this help message and exit --foo int @@ -545,7 +544,7 @@ >>> parser.print_help() usage: PROG [-h] [-f FOO] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit -f FOO old foo help --foo FOO new foo help @@ -574,7 +573,7 @@ $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help @@ -587,7 +586,7 @@ >>> parser.print_help() usage: PROG [--foo FOO] - optional arguments: + options: --foo FOO foo help The help option is typically ``-h/--help``. The exception to this is @@ -600,7 +599,7 @@ >>> parser.print_help() usage: PROG [+h] - optional arguments: + options: +h, ++help show this help message and exit @@ -632,7 +631,7 @@ * choices_ - A container of the allowable values for the argument. * required_ - Whether or not the command-line option may be omitted - (optionals only). + (options only). * help_ - A brief description of what the argument does. @@ -647,11 +646,11 @@ name or flags ^^^^^^^^^^^^^ -The :meth:`~ArgumentParser.add_argument` method must know whether an optional -argument, like ``-f`` or ``--foo``, or a positional argument, like a list of +The :meth:`~ArgumentParser.add_argument` method must know whether an option, +like ``-f`` or ``--foo``, or a positional argument, like a list of filenames, is expected. The first arguments passed to :meth:`~ArgumentParser.add_argument` must therefore be either a series of -flags, or a simple argument name. For example, an optional argument could +flags, or a simple argument name. For example, an option could be created like:: >>> parser.add_argument('-f', '--foo') @@ -660,7 +659,7 @@ >>> parser.add_argument('bar') -When :meth:`~ArgumentParser.parse_args` is called, optional arguments will be +When :meth:`~ArgumentParser.parse_args` is called, options will be identified by the ``-`` prefix, and the remaining arguments will be assumed to be positional:: @@ -696,7 +695,7 @@ * ``'store_const'`` - This stores the value specified by the const_ keyword argument. (Note that the const_ keyword argument defaults to the rather unhelpful ``None``.) The ``'store_const'`` action is most commonly used with - optional arguments that specify some sort of flag. For example:: + options that specify some sort of flag. For example:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_const', const=42) @@ -806,7 +805,7 @@ * ``'?'``. One argument will be consumed from the command line if possible, and produced as a single item. If no command-line argument is present, the value from - default_ will be produced. Note that for optional arguments, there is an + default_ will be produced. Note that for options, there is an additional case - the option string is present but not followed by a command-line argument. In this case the value from const_ will be produced. Some examples to illustrate this:: @@ -838,7 +837,7 @@ * ``'*'``. All command-line arguments present are gathered into a list. Note that it generally doesn't make much sense to have more than one positional argument - with ``nargs='*'``, but multiple optional arguments with ``nargs='*'`` is + with ``nargs='*'``, but multiple options with ``nargs='*'`` are possible. For example:: >>> parser = argparse.ArgumentParser() @@ -889,8 +888,8 @@ :meth:`~ArgumentParser.parse_args`. See the action_ description for examples. * When :meth:`~ArgumentParser.add_argument` is called with option strings - (like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional - argument that can be followed by zero or one command-line arguments. + (like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an option + that can be followed by zero or one command-line arguments. When parsing the command line, if the option string is encountered with no command-line argument following it, the value of ``const`` will be assumed instead. See the nargs_ description for examples. @@ -901,11 +900,11 @@ default ^^^^^^^ -All optional arguments and some positional arguments may be omitted at the +Some options and positional arguments may be omitted at the command line. The ``default`` keyword argument of :meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``, specifies what value should be used if the command-line argument is not present. -For optional arguments, the ``default`` value is used when the option string +For options, the ``default`` value is used when the option string was not present at the command line:: >>> parser = argparse.ArgumentParser() @@ -1065,11 +1064,6 @@ :meth:`~ArgumentParser.parse_args` will report an error if that option is not present at the command line. -.. note:: - - Required options are generally considered bad form because users expect - *options* to be *optional*, and thus they should be avoided when possible. - help ^^^^ @@ -1090,7 +1084,7 @@ positional arguments: bar one of the bars to be frobbled - optional arguments: + options: -h, --help show this help message and exit --foo foo the bars before frobbling @@ -1108,7 +1102,7 @@ positional arguments: bar the bar to frobble (default: 42) - optional arguments: + options: -h, --help show this help message and exit As the help string supports %-formatting, if you want a literal ``%`` to appear @@ -1122,7 +1116,7 @@ >>> parser.print_help() usage: frobble [-h] - optional arguments: + options: -h, --help show this help message and exit @@ -1132,10 +1126,10 @@ When :class:`ArgumentParser` generates help messages, it needs some way to refer to each expected argument. By default, ArgumentParser objects use the dest_ value as the "name" of each object. By default, for positional argument -actions, the dest_ value is used directly, and for optional argument actions, +actions, the dest_ value is used directly, and for option actions, the dest_ value is uppercased. So, a single positional argument with ``dest='bar'`` will be referred to as ``bar``. A single -optional argument ``--foo`` that should be followed by a single command-line argument +option ``--foo`` that should be followed by a single command-line argument will be referred to as ``FOO``. An example:: >>> parser = argparse.ArgumentParser() @@ -1149,7 +1143,7 @@ positional arguments: bar - optional arguments: + options: -h, --help show this help message and exit --foo FOO @@ -1166,7 +1160,7 @@ positional arguments: XXX - optional arguments: + options: -h, --help show this help message and exit --foo YYY @@ -1184,7 +1178,7 @@ >>> parser.print_help() usage: PROG [-h] [-x X X] [--foo bar baz] - optional arguments: + options: -h, --help show this help message and exit -x X X --foo bar baz @@ -1205,14 +1199,13 @@ >>> parser.parse_args('XXX'.split()) Namespace(bar='XXX') -For optional argument actions, the value of ``dest`` is normally inferred from +For option actions, the value of ``dest`` is normally inferred from the option strings. :class:`ArgumentParser` generates the value of ``dest`` by taking the first long option string and stripping away the initial ``--`` string. If no long option strings were supplied, ``dest`` will be derived from the first short option string by stripping the initial ``-`` character. Any -internal ``-`` characters will be converted to ``_`` characters to make sure -the string is a valid attribute name. The examples below illustrate this -behavior:: +internal ``-`` characters will be converted to ``_`` characters to help make +a valid attribute name. The examples below illustrate this behavior:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('-f', '--foo-bar', '--foo') @@ -1573,7 +1566,7 @@ a a help b b help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -1583,13 +1576,13 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit >>> parser.parse_args(['b', '--help']) usage: PROG b [-h] [--baz {X,Y,Z}] - optional arguments: + options: -h, --help show this help message and exit --baz {X,Y,Z} baz help @@ -1606,7 +1599,7 @@ >>> parser.parse_args(['-h']) usage: [-h] {foo,bar} ... - optional arguments: + options: -h, --help show this help message and exit subcommands: @@ -1715,7 +1708,7 @@ .. method:: ArgumentParser.add_argument_group(title=None, description=None) By default, :class:`ArgumentParser` groups command-line arguments into - "positional arguments" and "optional arguments" when displaying help + "positional arguments" and "options" when displaying help messages. When there is a better conceptual grouping of arguments than this default one, appropriate groups can be created using the :meth:`add_argument_group` method:: @@ -1758,7 +1751,7 @@ --bar BAR bar help Note that any arguments not in your user-defined groups will end up back - in the usual "positional arguments" and "optional arguments" sections. + in the usual "positional arguments" and "options" sections. Mutual exclusion diff -r 55e5be11264e Lib/argparse.py --- a/Lib/argparse.py Mon Dec 15 17:19:27 2014 -0800 +++ b/Lib/argparse.py Tue Dec 16 05:17:45 2014 +0000 @@ -4,7 +4,7 @@ This module is an optparse-inspired command-line parsing library that: - - handles both optional and positional arguments + - handles both options and positional arguments - produces highly informative usage messages - supports parsers that dispatch to sub-parsers @@ -27,7 +27,7 @@ - ArgumentParser -- The main entry point for command-line parsing. As the example above shows, the add_argument() method is used to populate - the parser with actions for optional and positional arguments. Then + the parser with actions for options and positional arguments. Then the parse_args() method is invoked to convert the args at the command-line into an object with attributes. @@ -294,26 +294,26 @@ if usage is not None: usage = usage % dict(prog=self._prog) - # if no optionals or positionals are available, usage is just prog + # if no options or positionals are available, usage is just prog elif usage is None and not actions: usage = '%(prog)s' % dict(prog=self._prog) - # if optionals and positionals are available, calculate usage + # if options and positionals are available, calculate usage elif usage is None: prog = '%(prog)s' % dict(prog=self._prog) - # split optionals from positionals - optionals = [] + # split options from positionals + options = [] positionals = [] for action in actions: if action.option_strings: - optionals.append(action) + options.append(action) else: positionals.append(action) # build full usage string format = self._format_actions_usage - action_usage = format(optionals + positionals, groups) + action_usage = format(options + positionals, groups) usage = ' '.join([s for s in [prog, action_usage] if s]) # wrap the usage parts if it's too long @@ -322,7 +322,7 @@ # break usage into wrappable parts part_regexp = r'\(.*?\)+|\[.*?\]+|\S+' - opt_usage = format(optionals, groups) + opt_usage = format(options, groups) pos_usage = format(positionals, groups) opt_parts = _re.findall(part_regexp, opt_usage) pos_parts = _re.findall(part_regexp, pos_usage) @@ -350,7 +350,7 @@ lines[0] = lines[0][len(indent):] return lines - # if prog is short, follow it with optionals or positionals + # if prog is short, follow it with options or positionals if len(prefix) + len(prog) <= 0.75 * text_width: indent = ' ' * (len(prefix) + len(prog) + 1) if opt_parts: @@ -437,15 +437,15 @@ else: option_string = action.option_strings[0] - # if the Optional doesn't take a value, format is: + # if the option doesn't take a value, format is: # -s or --long if action.nargs == 0: part = '%s' % option_string - # if the Optional takes a value, format is: + # if the option takes a value, format is: # -s ARGS or --long ARGS else: - default = self._get_default_metavar_for_optional(action) + default = self._get_default_metavar_for_option(action) args_string = self._format_args(action, default) part = '%s %s' % (option_string, args_string) @@ -538,15 +538,15 @@ else: parts = [] - # if the Optional doesn't take a value, format is: + # if the option doesn't take a value, format is: # -s, --long if action.nargs == 0: parts.extend(action.option_strings) - # if the Optional takes a value, format is: + # if the option takes a value, format is: # -s ARGS, --long ARGS else: - default = self._get_default_metavar_for_optional(action) + default = self._get_default_metavar_for_option(action) args_string = self._format_args(action, default) for option_string in action.option_strings: parts.append('%s %s' % (option_string, args_string)) @@ -623,7 +623,7 @@ def _get_help_string(self, action): return action.help - def _get_default_metavar_for_optional(self, action): + def _get_default_metavar_for_option(self, action): return action.dest.upper() def _get_default_metavar_for_positional(self, action): @@ -677,7 +677,7 @@ provided by the class are considered an implementation detail. """ - def _get_default_metavar_for_optional(self, action): + def _get_default_metavar_for_option(self, action): return action.type.__name__ def _get_default_metavar_for_positional(self, action): @@ -703,7 +703,7 @@ class ArgumentError(Exception): - """An error from creating or using an argument (optional or positional). + """An error from creating or using an argument (option or positional). The string value of this exception is the message, augmented with information about the argument that caused it. @@ -773,8 +773,7 @@ collection. - required -- True if the action must always be specified at the - command line. This is only meaningful for optional command-line - arguments. + command line. This is only meaningful for command-line options. - help -- The help string describing the argument. @@ -1190,7 +1189,7 @@ return '%s(%s)' % (type(self).__name__, args_str) # =========================== -# Optional and Positional Parsing +# Option and Positional Parsing # =========================== class Namespace(_AttributeHolder): @@ -1265,9 +1264,9 @@ # determines whether an "option" looks like a negative number self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$') - # whether or not there are any optionals that look like negative + # whether or not there are any options that look like negative # numbers -- uses a list so it can be shared and edited - self._has_negative_number_optionals = [] + self._has_negative_number_options = [] # ==================== # Registration methods @@ -1316,9 +1315,9 @@ raise ValueError('dest supplied twice for positional argument') kwargs = self._get_positional_kwargs(*args, **kwargs) - # otherwise, we're adding an optional argument + # otherwise, we're adding an option else: - kwargs = self._get_optional_kwargs(*args, **kwargs) + kwargs = self._get_option_kwargs(*args, **kwargs) # if no default was supplied, use the parser-level default if 'default' not in kwargs: @@ -1373,8 +1372,8 @@ # set the flag if any option strings look like negative numbers for option_string in action.option_strings: if self._negative_number_matcher.match(option_string): - if not self._has_negative_number_optionals: - self._has_negative_number_optionals.append(True) + if not self._has_negative_number_options: + self._has_negative_number_options.append(True) # return the created action return action @@ -1438,7 +1437,7 @@ # return the keyword arguments with no option strings return dict(kwargs, dest=dest, option_strings=[]) - def _get_optional_kwargs(self, *args, **kwargs): + def _get_option_kwargs(self, *args, **kwargs): # determine short and long option strings option_strings = [] long_option_strings = [] @@ -1490,16 +1489,16 @@ def _check_conflict(self, action): # find all options that conflict with this option - confl_optionals = [] + confl_options = [] for option_string in action.option_strings: if option_string in self._option_string_actions: - confl_optional = self._option_string_actions[option_string] - confl_optionals.append((option_string, confl_optional)) + confl_option = self._option_string_actions[option_string] + confl_options.append((option_string, confl_option)) # resolve any conflicts - if confl_optionals: + if confl_options: conflict_handler = self._get_handler() - conflict_handler(action, confl_optionals) + conflict_handler(action, confl_options) def _handle_conflict_error(self, action, conflicting_actions): message = ngettext('conflicting option string: %s', @@ -1545,8 +1544,8 @@ self._actions = container._actions self._option_string_actions = container._option_string_actions self._defaults = container._defaults - self._has_negative_number_optionals = \ - container._has_negative_number_optionals + self._has_negative_number_options = \ + container._has_negative_number_options self._mutually_exclusive_groups = container._mutually_exclusive_groups def _add_action(self, action): @@ -1589,7 +1588,7 @@ - epilog -- Text following the argument descriptions - parents -- Parsers whose arguments should be copied into this one - formatter_class -- HelpFormatter class for printing help messages - - prefix_chars -- Characters that prefix optional arguments + - prefix_chars -- Characters that prefix options - fromfile_prefix_chars -- Characters that prefix files containing additional arguments - argument_default -- The default value for all arguments @@ -1629,7 +1628,7 @@ add_group = self.add_argument_group self._positionals = add_group(_('positional arguments')) - self._optionals = add_group(_('optional arguments')) + self._options = add_group(_('options')) self._subparsers = None # register types @@ -1671,7 +1670,7 @@ return [(name, getattr(self, name)) for name in names] # ================================== - # Optional/Positional adding methods + # Option/Positional adding methods # ================================== def add_subparsers(self, **kwargs): if self._subparsers is not None: @@ -1688,7 +1687,7 @@ self._subparsers = self._positionals # prog defaults to the usage message of this parser, skipping - # optional arguments and with no "usage:" prefix + # options and with no "usage:" prefix if kwargs.get('prog') is None: formatter = self._get_formatter() positionals = self._get_positional_actions() @@ -1706,16 +1705,11 @@ def _add_action(self, action): if action.option_strings: - self._optionals._add_action(action) + self._options._add_action(action) else: self._positionals._add_action(action) return action - def _get_optional_actions(self): - return [action - for action in self._actions - if action.option_strings] - def _get_positional_actions(self): return [action for action in self._actions @@ -1798,7 +1792,7 @@ # otherwise, add the arg to the arg strings # and note the index if it was an option else: - option_tuple = self._parse_optional(arg_string) + option_tuple = self._parse_option(arg_string) if option_tuple is None: pattern = 'A' else: @@ -1833,26 +1827,26 @@ if argument_values is not SUPPRESS: action(self, namespace, argument_values, option_string) - # function to convert arg_strings into an optional action - def consume_optional(start_index): - - # get the optional identified at this index + # function to convert arg_strings into an option action + def consume_option(start_index): + + # get the option identified at this index option_tuple = option_string_indices[start_index] action, option_string, explicit_arg = option_tuple - # identify additional optionals in the same arg string + # identify additional options in the same arg string # (e.g. -xyz is the same as -x -y -z if no args are required) match_argument = self._match_argument action_tuples = [] while True: - # if we found no optional action, skip it + # if we found no option action, skip it if action is None: extras.append(arg_strings[start_index]) return start_index + 1 # if there is an explicit argument, try to match the - # optional's string arguments to only this + # option's string arguments to only this if explicit_arg is not None: arg_count = match_argument(action, 'A') @@ -1865,9 +1859,9 @@ char = option_string[0] option_string = char + explicit_arg[0] new_explicit_arg = explicit_arg[1:] or None - optionals_map = self._option_string_actions - if option_string in optionals_map: - action = optionals_map[option_string] + options_map = self._option_string_actions + if option_string in options_map: + action = options_map[option_string] explicit_arg = new_explicit_arg else: msg = _('ignored explicit argument %r') @@ -1888,7 +1882,7 @@ raise ArgumentError(action, msg % explicit_arg) # if there is no explicit argument, try to match the - # optional's string arguments with the following strings + # option's string arguments with the following strings # if successful, exit the loop else: start = start_index + 1 @@ -1899,8 +1893,8 @@ action_tuples.append((action, args, option_string)) break - # add the Optional to the list and return the index at which - # the Optional's string args stopped + # add the option to the list and return the index at which + # the option's string args stopped assert action_tuples for action, args, option_string in action_tuples: take_action(action, args, option_string) @@ -1929,7 +1923,7 @@ positionals[:] = positionals[len(arg_counts):] return start_index - # consume Positionals and Optionals alternately, until we have + # consume Positionals and Options alternately, until we have # passed the last option string extras = [] start_index = 0 @@ -1947,7 +1941,7 @@ if start_index != next_option_string_index: positionals_end_index = consume_positionals(start_index) - # only try to parse the next optional if we didn't consume + # only try to parse the next option if we didn't consume # the option string during the positionals parsing if positionals_end_index > start_index: start_index = positionals_end_index @@ -1962,10 +1956,10 @@ extras.extend(strings) start_index = next_option_string_index - # consume the next optional and any arguments for it - start_index = consume_optional(start_index) - - # consume any positionals following the last Optional + # consume the next option and any arguments for it + start_index = consume_option(start_index) + + # consume any positionals following the last option stop_index = consume_positionals(start_index) # if we didn't consume all the argument strings, there were extras @@ -2078,7 +2072,7 @@ # return the list of arg string counts return result - def _parse_optional(self, arg_string): + def _parse_option(self, arg_string): # if it's an empty string, it was meant to be a positional if not arg_string: return None @@ -2125,14 +2119,14 @@ # number, it was meant to be positional # unless there are negative-number-like options if self._negative_number_matcher.match(arg_string): - if not self._has_negative_number_optionals: + if not self._has_negative_number_options: return None # if it contains a space, it was meant to be a positional if ' ' in arg_string: return None - # it was meant to be an optional but there is no such option + # it was meant to be an option but there is no such option # in this parser (though it might be a valid option in a subparser) return None, arg_string, None @@ -2213,7 +2207,7 @@ else: nargs_pattern = '(-*%s-*)' % '-*'.join('A' * nargs) - # if this is an optional action, -- is not allowed + # if this is an option action, -- is not allowed if action.option_strings: nargs_pattern = nargs_pattern.replace('-*', '') nargs_pattern = nargs_pattern.replace('-', '') @@ -2329,7 +2323,7 @@ # description formatter.add_text(self.description) - # positionals, optionals and user-defined groups + # positionals, options and user-defined groups for action_group in self._action_groups: formatter.start_section(action_group.title) formatter.add_text(action_group.description) diff -r 55e5be11264e Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Mon Dec 15 17:19:27 2014 -0800 +++ b/Lib/test/test_argparse.py Tue Dec 16 05:17:45 2014 +0000 @@ -157,7 +157,7 @@ cls.parser_class = ErrorRaisingArgumentParser # --------------------------------------- - # functions for adding optional arguments + # functions for adding arguments # --------------------------------------- def no_groups(parser, argument_signatures): """Add all arguments directly to the parser""" @@ -192,7 +192,7 @@ finally: sys.argv = old_sys_argv - # class that holds the combination of one optional argument + # class that holds the combination of one argument # addition method and one arg parsing method class AddTests(object): @@ -237,7 +237,7 @@ result_ns = self._parse_args(parser, args) tester.assertEqual(expected_ns, result_ns) - # add tests for each combination of an optionals adding method + # add tests for each combination of an arguments adding method # and an arg parsing method for add_arguments in [no_groups, one_group, many_groups]: for parse_args in [listargs, sysargs]: @@ -247,11 +247,11 @@ ParserTestCase = ParserTesterMetaclass('ParserTestCase', bases, {}) # =============== -# Optionals tests +# Options tests # =============== -class TestOptionalsSingleDash(ParserTestCase): - """Test an Optional with a single-dash option string""" +class TestOptionsSingleDash(ParserTestCase): + """Test an option with a single-dash option string""" argument_signatures = [Sig('-x')] failures = ['-x', 'a', '--foo', '-x --foo', '-x -y'] @@ -264,8 +264,8 @@ ] -class TestOptionalsSingleDashCombined(ParserTestCase): - """Test an Optional with a single-dash option string""" +class TestOptionsSingleDashCombined(ParserTestCase): + """Test an option with a single-dash option string""" argument_signatures = [ Sig('-x', action='store_true'), @@ -290,8 +290,8 @@ ] -class TestOptionalsSingleDashLong(ParserTestCase): - """Test an Optional with a multi-character single-dash option string""" +class TestOptionsSingleDashLong(ParserTestCase): + """Test an option with a multi-character single-dash option string""" argument_signatures = [Sig('-foo')] failures = ['-foo', 'a', '--foo', '-foo --foo', '-foo -y', '-fooa'] @@ -304,8 +304,8 @@ ] -class TestOptionalsSingleDashSubsetAmbiguous(ParserTestCase): - """Test Optionals where option strings are subsets of each other""" +class TestOptionsSingleDashSubsetAmbiguous(ParserTestCase): + """Test options where option strings are subsets of each other""" argument_signatures = [Sig('-f'), Sig('-foobar'), Sig('-foorab')] failures = ['-f', '-foo', '-fo', '-foo b', '-foob', '-fooba', '-foora'] @@ -320,8 +320,8 @@ ] -class TestOptionalsSingleDashAmbiguous(ParserTestCase): - """Test Optionals that partially match but are not subsets""" +class TestOptionsSingleDashAmbiguous(ParserTestCase): + """Test options that partially match but are not subsets""" argument_signatures = [Sig('-foobar'), Sig('-foorab')] failures = ['-f', '-f a', '-fa', '-foa', '-foo', '-fo', '-foo b'] @@ -336,8 +336,8 @@ ] -class TestOptionalsNumeric(ParserTestCase): - """Test an Optional with a short opt string""" +class TestOptionsNumeric(ParserTestCase): + """Test an option with a short opt string""" argument_signatures = [Sig('-1', dest='one')] failures = ['-1', 'a', '-1 --foo', '-1 -y', '-1 -1', '-1 -2'] @@ -349,8 +349,8 @@ ] -class TestOptionalsDoubleDash(ParserTestCase): - """Test an Optional with a double-dash option string""" +class TestOptionsDoubleDash(ParserTestCase): + """Test an option with a double-dash option string""" argument_signatures = [Sig('--foo')] failures = ['--foo', '-f', '-f a', 'a', '--foo -x', '--foo --bar'] @@ -363,7 +363,7 @@ ] -class TestOptionalsDoubleDashPartialMatch(ParserTestCase): +class TestOptionsDoubleDashPartialMatch(ParserTestCase): """Tests partial matching with a double-dash option string""" argument_signatures = [ @@ -381,7 +381,7 @@ ] -class TestOptionalsDoubleDashPrefixMatch(ParserTestCase): +class TestOptionsDoubleDashPrefixMatch(ParserTestCase): """Tests when one double-dash option string is a prefix of another""" argument_signatures = [ @@ -400,8 +400,8 @@ ] -class TestOptionalsSingleDoubleDash(ParserTestCase): - """Test an Optional with single- and double-dash option strings""" +class TestOptionsSingleDoubleDash(ParserTestCase): + """Test an option with single- and double-dash option strings""" argument_signatures = [ Sig('-f', action='store_true'), @@ -419,8 +419,8 @@ ] -class TestOptionalsAlternatePrefixChars(ParserTestCase): - """Test an Optional with option strings with custom prefixes""" +class TestOptionsAlternatePrefixChars(ParserTestCase): + """Test an option with option strings with custom prefixes""" parser_signature = Sig(prefix_chars='+:/', add_help=False) argument_signatures = [ @@ -439,7 +439,7 @@ ] -class TestOptionalsAlternatePrefixCharsAddedHelp(ParserTestCase): +class TestOptionsAlternatePrefixCharsAddedHelp(ParserTestCase): """When ``-`` not in prefix_chars, default operators created for help should use the prefix_chars in use rather than - or -- http://bugs.python.org/issue9444""" @@ -461,8 +461,8 @@ ] -class TestOptionalsAlternatePrefixCharsMultipleShortArgs(ParserTestCase): - """Verify that Optionals must be called with their defined prefixes""" +class TestOptionsAlternatePrefixCharsMultipleShortArgs(ParserTestCase): + """Verify that options must be called with their defined prefixes""" parser_signature = Sig(prefix_chars='+-', add_help=False) argument_signatures = [ @@ -484,7 +484,7 @@ ] -class TestOptionalsShortLong(ParserTestCase): +class TestOptionsShortLong(ParserTestCase): """Test a combination of single- and double-dash option strings""" argument_signatures = [ @@ -500,7 +500,7 @@ ] -class TestOptionalsDest(ParserTestCase): +class TestOptionsDest(ParserTestCase): """Tests various means of setting destination""" argument_signatures = [Sig('--foo-bar'), Sig('--baz', dest='zabbaz')] @@ -513,8 +513,8 @@ ] -class TestOptionalsDefault(ParserTestCase): - """Tests specifying a default for an Optional""" +class TestOptionsDefault(ParserTestCase): + """Tests specifying a default for an option""" argument_signatures = [Sig('-x'), Sig('-y', default=42)] failures = ['a'] @@ -525,8 +525,8 @@ ] -class TestOptionalsNargsDefault(ParserTestCase): - """Tests not specifying the number of args for an Optional""" +class TestOptionsNargsDefault(ParserTestCase): + """Tests not specifying the number of args for an option""" argument_signatures = [Sig('-x')] failures = ['a', '-x'] @@ -536,8 +536,8 @@ ] -class TestOptionalsNargs1(ParserTestCase): - """Tests specifying the 1 arg for an Optional""" +class TestOptionsNargs1(ParserTestCase): + """Tests specifying the 1 arg for an option""" argument_signatures = [Sig('-x', nargs=1)] failures = ['a', '-x'] @@ -547,8 +547,8 @@ ] -class TestOptionalsNargs3(ParserTestCase): - """Tests specifying the 3 args for an Optional""" +class TestOptionsNargs3(ParserTestCase): + """Tests specifying the 3 args for an option""" argument_signatures = [Sig('-x', nargs=3)] failures = ['a', '-x', '-x a', '-x a b', 'a -x', 'a -x b'] @@ -558,8 +558,8 @@ ] -class TestOptionalsNargsOptional(ParserTestCase): - """Tests specifying an Optional arg for an Optional""" +class TestOptionsNargsOptional(ParserTestCase): + """Tests specifying an optional arg for an option""" argument_signatures = [ Sig('-w', nargs='?'), @@ -581,8 +581,8 @@ ] -class TestOptionalsNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" +class TestOptionsNargsZeroOrMore(ParserTestCase): + """Tests specifying an args for an option that accepts zero or more""" argument_signatures = [ Sig('-x', nargs='*'), @@ -600,8 +600,8 @@ ] -class TestOptionalsNargsOneOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts one or more""" +class TestOptionsNargsOneOrMore(ParserTestCase): + """Tests specifying an args for an option that accepts one or more""" argument_signatures = [ Sig('-x', nargs='+'), @@ -617,8 +617,8 @@ ] -class TestOptionalsChoices(ParserTestCase): - """Tests specifying the choices for an Optional""" +class TestOptionsChoices(ParserTestCase): + """Tests specifying the choices for an option""" argument_signatures = [ Sig('-f', choices='abc'), @@ -634,8 +634,8 @@ ] -class TestOptionalsRequired(ParserTestCase): - """Tests the an optional action that is required""" +class TestOptionsRequired(ParserTestCase): + """Tests an option action that is required""" argument_signatures = [ Sig('-x', type=int, required=True), @@ -647,8 +647,8 @@ ] -class TestOptionalsActionStore(ParserTestCase): - """Tests the store action for an Optional""" +class TestOptionsActionStore(ParserTestCase): + """Tests the store action for an option""" argument_signatures = [Sig('-x', action='store')] failures = ['a', 'a -x'] @@ -658,8 +658,8 @@ ] -class TestOptionalsActionStoreConst(ParserTestCase): - """Tests the store_const action for an Optional""" +class TestOptionsActionStoreConst(ParserTestCase): + """Tests the store_const action for an option""" argument_signatures = [Sig('-y', action='store_const', const=object)] failures = ['a'] @@ -669,8 +669,8 @@ ] -class TestOptionalsActionStoreFalse(ParserTestCase): - """Tests the store_false action for an Optional""" +class TestOptionsActionStoreFalse(ParserTestCase): + """Tests the store_false action for an option""" argument_signatures = [Sig('-z', action='store_false')] failures = ['a', '-za', '-z a'] @@ -680,8 +680,8 @@ ] -class TestOptionalsActionStoreTrue(ParserTestCase): - """Tests the store_true action for an Optional""" +class TestOptionsActionStoreTrue(ParserTestCase): + """Tests the store_true action for an option""" argument_signatures = [Sig('--apple', action='store_true')] failures = ['a', '--apple=b', '--apple b'] @@ -691,8 +691,8 @@ ] -class TestOptionalsActionAppend(ParserTestCase): - """Tests the append action for an Optional""" +class TestOptionsActionAppend(ParserTestCase): + """Tests the append action for an option""" argument_signatures = [Sig('--baz', action='append')] failures = ['a', '--baz', 'a --baz', '--baz a b'] @@ -703,8 +703,8 @@ ] -class TestOptionalsActionAppendWithDefault(ParserTestCase): - """Tests the append action for an Optional""" +class TestOptionsActionAppendWithDefault(ParserTestCase): + """Tests the append action for an option""" argument_signatures = [Sig('--baz', action='append', default=['X'])] failures = ['a', '--baz', 'a --baz', '--baz a b'] @@ -715,8 +715,8 @@ ] -class TestOptionalsActionAppendConst(ParserTestCase): - """Tests the append_const action for an Optional""" +class TestOptionsActionAppendConst(ParserTestCase): + """Tests the append_const action for an option""" argument_signatures = [ Sig('-b', action='append_const', const=Exception), @@ -730,8 +730,8 @@ ] -class TestOptionalsActionAppendConstWithDefault(ParserTestCase): - """Tests the append_const action for an Optional""" +class TestOptionsActionAppendConstWithDefault(ParserTestCase): + """Tests the append_const action for an option""" argument_signatures = [ Sig('-b', action='append_const', const=Exception, default=['X']), @@ -745,8 +745,8 @@ ] -class TestOptionalsActionCount(ParserTestCase): - """Tests the count action for an Optional""" +class TestOptionsActionCount(ParserTestCase): + """Tests the count action for an option""" argument_signatures = [Sig('-x', action='count')] failures = ['a', '-x a', '-x b', '-x a -x b'] @@ -1146,10 +1146,10 @@ ] # ======================================== -# Combined optionals and positionals tests +# Combined options and positionals tests # ======================================== -class TestOptionalsNumericAndPositionals(ParserTestCase): +class TestOptionsNumericAndPositionals(ParserTestCase): """Tests negative number args when numeric options are present""" argument_signatures = [ @@ -1165,7 +1165,7 @@ ] -class TestOptionalsAlmostNumericAndPositionals(ParserTestCase): +class TestOptionsAlmostNumericAndPositionals(ParserTestCase): """Tests negative number args when almost numeric options are present""" argument_signatures = [ @@ -1221,7 +1221,7 @@ class TestNargsZeroOrMore(ParserTestCase): - """Tests specifying an args for an Optional that accepts zero or more""" + """Tests specifying args for an option that accepts zero or more""" argument_signatures = [Sig('-x', nargs='*'), Sig('y', nargs='*')] failures = [] @@ -1668,7 +1668,7 @@ class TestActionUserDefined(ParserTestCase): """Test a user-defined option/argument action""" - class OptionalAction(argparse.Action): + class OptionAction(argparse.Action): def __call__(self, parser, namespace, value, option_string=None): try: @@ -1718,7 +1718,7 @@ setattr(namespace, 'badger', value) argument_signatures = [ - Sig('-s', dest='spam', action=OptionalAction, + Sig('-s', dest='spam', action=OptionAction, type=float, default=0.25), Sig('badger', action=PositionalAction, type=int, nargs='?', default=2), @@ -1889,7 +1889,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: -h, --help show this help message and exit --foo foo help ''')) @@ -1908,7 +1908,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: -h, --help show this help message and exit ++foo foo help ''')) @@ -1927,7 +1927,7 @@ bar bar help {1,2,3} command help - optional arguments: + options: +h, ++help show this help message and exit ++foo foo help ''')) @@ -1948,7 +1948,7 @@ 2 2 help 3 3 help - optional arguments: + options: -h, --help show this help message and exit --foo foo help ''')) @@ -1973,7 +1973,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -1997,7 +1997,7 @@ positional arguments: {a,b,c} x help - optional arguments: + options: -h, --help show this help message and exit -w W w help ''')) @@ -2011,7 +2011,7 @@ positional arguments: z z help - optional arguments: + options: -h, --help show this help message and exit -y {1,2,3} y help ''')) @@ -2043,7 +2043,7 @@ positional arguments: bar bar help - optional arguments: + options: -h, --help show this help message and exit --foo foo help @@ -2231,7 +2231,7 @@ a z - optional arguments: + options: -h, --help show this help message and exit -b B --w W @@ -2261,7 +2261,7 @@ self.assertEqual(parser_help, textwrap.dedent('''\ usage: {}{}[-h] [-w W] [-x X] [-y Y | -z Z] - optional arguments: + options: -h, --help show this help message and exit -y Y -z Z @@ -2306,7 +2306,7 @@ expected = '''\ usage: PROG [-h] [--foo | --bar] [--soup | --nuts] - optional arguments: + options: -h, --help show this help message and exit --foo --bar @@ -2391,7 +2391,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit --bar BAR bar help --baz [BAZ] baz help @@ -2432,7 +2432,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit --abcde ABCDE abcde help --fghij FGHIJ fghij help @@ -2468,7 +2468,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit -y y help ''' @@ -2505,12 +2505,12 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit ''' -class TestMutuallyExclusiveOptionalAndPositional(MEMixin, TestCase): +class TestMutuallyExclusiveOptionAndPositional(MEMixin, TestCase): def get_parser(self, required): parser = ErrorRaisingArgumentParser(prog='PROG') @@ -2548,14 +2548,14 @@ positional arguments: badger BADGER - optional arguments: + options: -h, --help show this help message and exit --foo FOO --spam SPAM SPAM ''' -class TestMutuallyExclusiveOptionalsMixed(MEMixin, TestCase): +class TestMutuallyExclusiveOptionsMixed(MEMixin, TestCase): def get_parser(self, required): parser = ErrorRaisingArgumentParser(prog='PROG') @@ -2587,7 +2587,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit -x x help -a a help @@ -2626,7 +2626,7 @@ ''' help = '''\ - optional arguments: + options: -h, --help show this help message and exit Titled group: @@ -2637,7 +2637,7 @@ ''' -class TestMutuallyExclusiveOptionalsAndPositionalsMixed(MEMixin, TestCase): +class TestMutuallyExclusiveOptionsAndPositionalsMixed(MEMixin, TestCase): def get_parser(self, required): parser = ErrorRaisingArgumentParser(prog='PROG') @@ -2671,7 +2671,7 @@ x x help a a help - optional arguments: + options: -h, --help show this help message and exit -y y help -b b help @@ -2716,18 +2716,18 @@ pass -class TestMutuallyExclusiveOptionalAndPositionalParent( - MEPBase, TestMutuallyExclusiveOptionalAndPositional): +class TestMutuallyExclusiveOptionAndPositionalParent( + MEPBase, TestMutuallyExclusiveOptionAndPositional): pass -class TestMutuallyExclusiveOptionalsMixedParent( - MEPBase, TestMutuallyExclusiveOptionalsMixed): +class TestMutuallyExclusiveOptionsMixedParent( + MEPBase, TestMutuallyExclusiveOptionsMixed): pass -class TestMutuallyExclusiveOptionalsAndPositionalsMixedParent( - MEPBase, TestMutuallyExclusiveOptionalsAndPositionalsMixed): +class TestMutuallyExclusiveOptionsAndPositionalsMixedParent( + MEPBase, TestMutuallyExclusiveOptionsAndPositionalsMixed): pass # ================= @@ -2956,7 +2956,7 @@ HelpTestCase = TestHelpFormattingMetaclass('HelpTestCase', bases, {}) -class TestHelpBiggerOptionals(HelpTestCase): +class TestHelpBiggerOptions(HelpTestCase): """Make sure that argument help aligns when options are longer""" parser_signature = Sig(prog='PROG', description='DESCRIPTION', @@ -2980,7 +2980,7 @@ foo FOO HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x X HELP @@ -3003,9 +3003,9 @@ env.set("COLUMNS", '15') self.addCleanup(env.__exit__) - parser_signature = TestHelpBiggerOptionals.parser_signature - argument_signatures = TestHelpBiggerOptionals.argument_signatures - argument_group_signatures = TestHelpBiggerOptionals.argument_group_signatures + parser_signature = TestHelpBiggerOptions.parser_signature + argument_signatures = TestHelpBiggerOptions.argument_signatures + argument_group_signatures = TestHelpBiggerOptions.argument_group_signatures usage = '''\ usage: PROG [-h] @@ -3025,7 +3025,7 @@ bar BAR HELP - optional arguments: + options: -h, --help show this help @@ -3044,10 +3044,10 @@ EPILOG ''' - version = TestHelpBiggerOptionals.version - - -class TestHelpBiggerOptionalGroups(HelpTestCase): + version = TestHelpBiggerOptions.version + + +class TestHelpBiggerOptionGroups(HelpTestCase): """Make sure that argument help aligns when options are longer""" parser_signature = Sig(prog='PROG', description='DESCRIPTION', @@ -3075,7 +3075,7 @@ foo FOO HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x X HELP @@ -3116,7 +3116,7 @@ ekiekiekifekang EKI HELP bar BAR HELP - optional arguments: + options: -h, --help show this help message and exit -x X HELP --y Y Y HELP @@ -3163,7 +3163,7 @@ positional arguments: yyy normal y help - optional arguments: + options: -h, --help show this help message and exit -x XX oddly formatted -x help @@ -3203,7 +3203,7 @@ YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH - optional arguments: + options: -h, --help show this help message and exit -x XX XHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH HXXHH \ HXXHH HXXHH @@ -3246,7 +3246,7 @@ YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YHYH YH - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3301,7 +3301,7 @@ b b c c - optional arguments: + options: -h, --help show this help message and exit -w W [W ...] w -x [X [X ...]] x @@ -3367,7 +3367,7 @@ a b - optional arguments: + options: -h, --help show this help message and exit -w W -x X @@ -3376,7 +3376,7 @@ class TestHelpUsageLongProgOptionsWrap(HelpTestCase): - """Test usage messages where the prog is long and the optionals wrap""" + """Test usage messages where the prog is long and the options wrap""" parser_signature = Sig(prog='P' * 60) argument_signatures = [ @@ -3401,7 +3401,7 @@ a b - optional arguments: + options: -h, --help show this help message and exit -w WWWWWWWWWWWWWWWWWWWWWWWWW -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3436,8 +3436,8 @@ version = '' -class TestHelpUsageOptionalsWrap(HelpTestCase): - """Test usage messages where the optionals wrap""" +class TestHelpUsageOptionsWrap(HelpTestCase): + """Test usage messages where the options wrap""" parser_signature = Sig(prog='PROG') argument_signatures = [ @@ -3464,7 +3464,7 @@ b c - optional arguments: + options: -h, --help show this help message and exit -w WWWWWWWWWWWWWWWWWWWWWWWWW -x XXXXXXXXXXXXXXXXXXXXXXXXX @@ -3499,7 +3499,7 @@ bbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc - optional arguments: + options: -h, --help show this help message and exit -x X -y Y @@ -3508,8 +3508,8 @@ version = '' -class TestHelpUsageOptionalsPositionalsWrap(HelpTestCase): - """Test usage messages where the optionals and positionals wrap""" +class TestHelpUsageOptionsPositionalsWrap(HelpTestCase): + """Test usage messages where the options and positionals wrap""" parser_signature = Sig(prog='PROG') argument_signatures = [ @@ -3535,7 +3535,7 @@ bbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc - optional arguments: + options: -h, --help show this help message and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX -y YYYYYYYYYYYYYYYYYYYYYYYYY @@ -3544,8 +3544,8 @@ version = '' -class TestHelpUsageOptionalsOnlyWrap(HelpTestCase): - """Test usage messages where there are only optionals and they wrap""" +class TestHelpUsageOptionsOnlyWrap(HelpTestCase): + """Test usage messages where there are only options and they wrap""" parser_signature = Sig(prog='PROG') argument_signatures = [ @@ -3561,7 +3561,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit -x XXXXXXXXXXXXXXXXXXXXXXXXX -y YYYYYYYYYYYYYYYYYYYYYYYYY @@ -3626,7 +3626,7 @@ spam spam PROG None badger badger PROG 0.5 - optional arguments: + options: -h, --help show this help message and exit -x X x PROG None int % -y y PROG 42 XXX @@ -3651,7 +3651,7 @@ ''') help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit ''' version = '' @@ -3683,7 +3683,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3691,8 +3691,8 @@ version = '' -class TestHelpSuppressOptional(HelpTestCase): - """Test that optional arguments can be suppressed in help messages""" +class TestHelpSuppressOption(HelpTestCase): + """Test that options can be suppressed in help messages""" parser_signature = Sig(prog='PROG', add_help=False) argument_signatures = [ @@ -3711,8 +3711,8 @@ version = '' -class TestHelpSuppressOptionalGroup(HelpTestCase): - """Test that optional groups can be suppressed in help messages""" +class TestHelpSuppressOptionGroup(HelpTestCase): + """Test that option groups can be suppressed in help messages""" parser_signature = Sig(prog='PROG') argument_signatures = [ @@ -3730,7 +3730,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3751,14 +3751,14 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' version = '' -class TestHelpRequiredOptional(HelpTestCase): +class TestHelpRequiredOption(HelpTestCase): """Test that required options don't look optional""" parser_signature = Sig(prog='PROG') @@ -3771,7 +3771,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help ''' @@ -3792,14 +3792,14 @@ ''' help = usage + '''\ - optional arguments: + options: ^^foo foo help ;b BAR, ;;bar BAR bar help ''' version = '' -class TestHelpNoHelpOptional(HelpTestCase): +class TestHelpNoHelpOption(HelpTestCase): """Test that the --help argument can be suppressed help messages""" parser_signature = Sig(prog='PROG', add_help=False) @@ -3816,13 +3816,13 @@ positional arguments: spam spam help - optional arguments: + options: --foo FOO foo help ''' version = '' -class TestHelpVersionOptional(HelpTestCase): +class TestHelpVersionOption(HelpTestCase): """Test that the --version argument can be suppressed help messages""" parser_signature = Sig(prog='PROG') @@ -3840,7 +3840,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit --foo FOO foo help @@ -3867,7 +3867,7 @@ positional arguments: spam - optional arguments: + options: -h, --help show this help message and exit --foo FOO ''' @@ -3891,7 +3891,7 @@ ''' help = usage + '''\ - optional arguments: + options: -h, --help show this help message and exit -w W1 [W2 ...] w -x [X1 [X2 ...]] x @@ -3935,7 +3935,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help should also appear as given here @@ -3984,7 +3984,7 @@ positional arguments: spam spam help - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help should not retain this odd formatting @@ -4026,7 +4026,7 @@ spam spam help badger badger help (default: wooden) - optional arguments: + options: -h, --help show this help message and exit --foo FOO foo help - oh and by the way, None --bar bar help (default: False) @@ -4051,7 +4051,7 @@ description - optional arguments: + options: -h, --help show this help message and exit -V, --version show program's version number and exit ''' @@ -4077,7 +4077,7 @@ positional arguments: {a,b,c,d,e} - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit ''' @@ -4118,7 +4118,7 @@ d d subcommand help e e subcommand help - optional arguments: + options: -h, --help show this help message and exit -v, --version show program's version number and exit ''' @@ -4151,7 +4151,7 @@ positional arguments: int - optional arguments: + options: -h, --help show this help message and exit -b custom_type -c SOME FLOAT @@ -4160,7 +4160,7 @@ # ===================================== -# Optional/Positional constructor tests +# Option/Positional constructor tests # ===================================== class TestInvalidArgumentConstructors(TestCase): @@ -4343,7 +4343,7 @@ self.assertEqual(parser.format_help(), textwrap.dedent('''\ usage: PROG [-h] [-x X] - optional arguments: + options: -h, --help show this help message and exit -x X NEW X ''')) @@ -4353,7 +4353,7 @@ self.assertEqual(parser.format_help(), textwrap.dedent('''\ usage: PROG [-h] [-x X] [--spam NEW_SPAM] - optional arguments: + options: -h, --help show this help message and exit -x X NEW X --spam NEW_SPAM @@ -4364,7 +4364,7 @@ # Help and Version option tests # ============================= -class TestOptionalsHelpVersionActions(TestCase): +class TestOptionsHelpVersionActions(TestCase): """Test the help and version actions""" def assertPrintHelpExit(self, parser, args_str): @@ -4441,13 +4441,13 @@ # ====================== class TestStrings(TestCase): - """Test str() and repr() on Optionals and Positionals""" + """Test str() and repr() on options and positionals""" def assertStringEqual(self, obj, result_string): for func in [str, repr]: self.assertEqual(func(obj), result_string) - def test_optional(self): + def test_option(self): option = argparse.Action( option_strings=['--foo', '-a', '-b'], dest='b', @@ -4607,7 +4607,7 @@ self.assertNotIn(msg, 'req_opt') self.assertRegex(msg, 'need_one') - def test_optional_optional_not_in_message(self): + def test_optional_option_not_in_message(self): parser = ErrorRaisingArgumentParser(prog='PROG', usage='') parser.add_argument('req_pos', type=str) parser.add_argument('--req_opt', type=int, required=True) @@ -4726,7 +4726,7 @@ parser.add_argument('x') parser.parse_args(['x']) - def test_optionals(self): + def test_options(self): parser = argparse.ArgumentParser() parser.add_argument('--foo') args, extras = parser.parse_known_args('--foo F --bar --baz'.split())