From 45559a4010a6cfdb0939c40340c80f9dd443aa5f Mon Sep 17 00:00:00 2001 From: Yuki Date: Sat, 3 Jun 2023 04:31:51 +0000 Subject: [PATCH 1/4] gh-101100: Fix reference to `parse_args` in `optparse.rst` --- Doc/library/optparse.rst | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index 5c02d8bc8835bf..b7f9f95f85633c 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -42,8 +42,8 @@ on the command-line, for example:: --file=outfile -q As it parses the command line, :mod:`optparse` sets attributes of the -``options`` object returned by :meth:`parse_args` based on user-supplied -command-line values. When :meth:`parse_args` returns from parsing this command +``options`` object returned by :meth:`~ArgumentParser.parse_args` based on user-supplied +command-line values. When :meth:`~ArgumentParser.parse_args` returns from parsing this command line, ``options.filename`` will be ``"outfile"`` and ``options.verbose`` will be ``False``. :mod:`optparse` supports both long and short options, allows short options to be merged together, and allows options to be associated with their @@ -285,10 +285,10 @@ program's command line:: (options, args) = parser.parse_args() -(If you like, you can pass a custom argument list to :meth:`parse_args`, but +(If you like, you can pass a custom argument list to :meth:`~ArgumentParser.parse_args`, but that's rarely necessary: by default it uses ``sys.argv[1:]``.) -:meth:`parse_args` returns two values: +:meth:`~ArgumentParser.parse_args` returns two values: * ``options``, an object containing values for all of your options---e.g. if ``--file`` takes a single string argument, then ``options.file`` will be the @@ -339,7 +339,7 @@ Now let's make up a fake command line and ask :mod:`optparse` to parse it:: When :mod:`optparse` sees the option string ``-f``, it consumes the next argument, ``foo.txt``, and stores it in ``options.filename``. So, after this -call to :meth:`parse_args`, ``options.filename`` is ``"foo.txt"``. +call to :meth:`~ArgumentParser.parse_args`, ``options.filename`` is ``"foo.txt"``. Some other option types supported by :mod:`optparse` are ``int`` and ``float``. Here's an option that expects an integer argument:: @@ -453,7 +453,8 @@ Again, the default value for ``verbose`` will be ``True``: the last default value supplied for any particular destination is the one that counts. A clearer way to specify default values is the :meth:`set_defaults` method of -OptionParser, which you can call at any time before calling :meth:`parse_args`:: +OptionParser, which you can call at any time before calling +:meth:`~ArgumentParser.parse_args`:: parser.set_defaults(verbose=True) parser.add_option(...) @@ -1338,7 +1339,7 @@ Parsing arguments ^^^^^^^^^^^^^^^^^ The whole point of creating and populating an OptionParser is to call its -:meth:`parse_args` method:: +:meth:`~ArgumentParser.parse_args` method:: (options, args) = parser.parse_args(args=None, values=None) @@ -1364,9 +1365,9 @@ and the return values are The most common usage is to supply neither keyword argument. If you supply ``values``, it will be modified with repeated :func:`setattr` calls (roughly one for every option argument stored to an option destination) and returned by -:meth:`parse_args`. +:meth:`~ArgumentParser.parse_args`. -If :meth:`parse_args` encounters any errors in the argument list, it calls the +If :meth:`~ArgumentParser.parse_args` encounters any errors in the argument list, it calls the OptionParser's :meth:`error` method with an appropriate end-user error message. This ultimately terminates your process with an exit status of 2 (the traditional Unix exit status for command-line errors). @@ -1661,7 +1662,7 @@ where the current list of leftover arguments, ie. arguments that have been consumed but are neither options nor option arguments. Feel free to modify ``parser.largs``, e.g. by adding more arguments to it. (This list will - become ``args``, the second return value of :meth:`parse_args`.) + become ``args``, the second return value of :meth:`~ArgumentParser.parse_args`.) ``parser.rargs`` the current list of remaining arguments, ie. with ``opt_str`` and From 1904084ead7cf762a18d480f5debe05101fcb5fe Mon Sep 17 00:00:00 2001 From: Yuki Date: Sat, 3 Jun 2023 05:05:36 +0000 Subject: [PATCH 2/4] fixup --- Doc/library/optparse.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index b7f9f95f85633c..d0e8a48ca58f3c 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -42,8 +42,8 @@ on the command-line, for example:: --file=outfile -q As it parses the command line, :mod:`optparse` sets attributes of the -``options`` object returned by :meth:`~ArgumentParser.parse_args` based on user-supplied -command-line values. When :meth:`~ArgumentParser.parse_args` returns from parsing this command +``options`` object returned by :meth:`~argparse.ArgumentParser.parse_args` based on user-supplied +command-line values. When :meth:`~argparse.ArgumentParser.parse_args` returns from parsing this command line, ``options.filename`` will be ``"outfile"`` and ``options.verbose`` will be ``False``. :mod:`optparse` supports both long and short options, allows short options to be merged together, and allows options to be associated with their @@ -285,10 +285,10 @@ program's command line:: (options, args) = parser.parse_args() -(If you like, you can pass a custom argument list to :meth:`~ArgumentParser.parse_args`, but +(If you like, you can pass a custom argument list to :meth:`~argparse.ArgumentParser.parse_args`, but that's rarely necessary: by default it uses ``sys.argv[1:]``.) -:meth:`~ArgumentParser.parse_args` returns two values: +:meth:`~argparse.ArgumentParser.parse_args` returns two values: * ``options``, an object containing values for all of your options---e.g. if ``--file`` takes a single string argument, then ``options.file`` will be the @@ -339,7 +339,7 @@ Now let's make up a fake command line and ask :mod:`optparse` to parse it:: When :mod:`optparse` sees the option string ``-f``, it consumes the next argument, ``foo.txt``, and stores it in ``options.filename``. So, after this -call to :meth:`~ArgumentParser.parse_args`, ``options.filename`` is ``"foo.txt"``. +call to :meth:`~argparse.ArgumentParser.parse_args`, ``options.filename`` is ``"foo.txt"``. Some other option types supported by :mod:`optparse` are ``int`` and ``float``. Here's an option that expects an integer argument:: @@ -454,7 +454,7 @@ value supplied for any particular destination is the one that counts. A clearer way to specify default values is the :meth:`set_defaults` method of OptionParser, which you can call at any time before calling -:meth:`~ArgumentParser.parse_args`:: +:meth:`~argparse.ArgumentParser.parse_args`:: parser.set_defaults(verbose=True) parser.add_option(...) @@ -1339,7 +1339,7 @@ Parsing arguments ^^^^^^^^^^^^^^^^^ The whole point of creating and populating an OptionParser is to call its -:meth:`~ArgumentParser.parse_args` method:: +:meth:`~argparse.ArgumentParser.parse_args` method:: (options, args) = parser.parse_args(args=None, values=None) @@ -1365,9 +1365,9 @@ and the return values are The most common usage is to supply neither keyword argument. If you supply ``values``, it will be modified with repeated :func:`setattr` calls (roughly one for every option argument stored to an option destination) and returned by -:meth:`~ArgumentParser.parse_args`. +:meth:`~argparse.ArgumentParser.parse_args`. -If :meth:`~ArgumentParser.parse_args` encounters any errors in the argument list, it calls the +If :meth:`~argparse.ArgumentParser.parse_args` encounters any errors in the argument list, it calls the OptionParser's :meth:`error` method with an appropriate end-user error message. This ultimately terminates your process with an exit status of 2 (the traditional Unix exit status for command-line errors). @@ -1662,7 +1662,7 @@ where the current list of leftover arguments, ie. arguments that have been consumed but are neither options nor option arguments. Feel free to modify ``parser.largs``, e.g. by adding more arguments to it. (This list will - become ``args``, the second return value of :meth:`~ArgumentParser.parse_args`.) + become ``args``, the second return value of :meth:`~argparse.ArgumentParser.parse_args`.) ``parser.rargs`` the current list of remaining arguments, ie. with ``opt_str`` and From 2182f3076c1580dd646497d6d7b42ae4ac3283aa Mon Sep 17 00:00:00 2001 From: Yuki Date: Wed, 28 Jun 2023 06:05:44 +0000 Subject: [PATCH 3/4] Fix reflecting reviews --- Doc/library/optparse.rst | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index d0e8a48ca58f3c..50ebeb6f3cb362 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -42,8 +42,8 @@ on the command-line, for example:: --file=outfile -q As it parses the command line, :mod:`optparse` sets attributes of the -``options`` object returned by :meth:`~argparse.ArgumentParser.parse_args` based on user-supplied -command-line values. When :meth:`~argparse.ArgumentParser.parse_args` returns from parsing this command +``options`` object returned by :meth:`~OptionParser.parse_args` based on user-supplied +command-line values. When :meth:`~OptionParser.parse_args` returns from parsing this command line, ``options.filename`` will be ``"outfile"`` and ``options.verbose`` will be ``False``. :mod:`optparse` supports both long and short options, allows short options to be merged together, and allows options to be associated with their @@ -285,10 +285,10 @@ program's command line:: (options, args) = parser.parse_args() -(If you like, you can pass a custom argument list to :meth:`~argparse.ArgumentParser.parse_args`, but +(If you like, you can pass a custom argument list to :meth:`~OptionParser.parse_args`, but that's rarely necessary: by default it uses ``sys.argv[1:]``.) -:meth:`~argparse.ArgumentParser.parse_args` returns two values: +:meth:`~OptionParser.parse_args` returns two values: * ``options``, an object containing values for all of your options---e.g. if ``--file`` takes a single string argument, then ``options.file`` will be the @@ -339,7 +339,7 @@ Now let's make up a fake command line and ask :mod:`optparse` to parse it:: When :mod:`optparse` sees the option string ``-f``, it consumes the next argument, ``foo.txt``, and stores it in ``options.filename``. So, after this -call to :meth:`~argparse.ArgumentParser.parse_args`, ``options.filename`` is ``"foo.txt"``. +call to :meth:`~OptionParser.parse_args`, ``options.filename`` is ``"foo.txt"``. Some other option types supported by :mod:`optparse` are ``int`` and ``float``. Here's an option that expects an integer argument:: @@ -454,7 +454,7 @@ value supplied for any particular destination is the one that counts. A clearer way to specify default values is the :meth:`set_defaults` method of OptionParser, which you can call at any time before calling -:meth:`~argparse.ArgumentParser.parse_args`:: +:meth:`~OptionParser.parse_args`:: parser.set_defaults(verbose=True) parser.add_option(...) @@ -1339,35 +1339,37 @@ Parsing arguments ^^^^^^^^^^^^^^^^^ The whole point of creating and populating an OptionParser is to call its -:meth:`~argparse.ArgumentParser.parse_args` method:: +:meth:`~OptionParser.parse_args` method. - (options, args) = parser.parse_args(args=None, values=None) +.. method:: OptionParser.parse_args(args=None, values=None) -where the input parameters are + Parse the command-line options found in *args*. -``args`` - the list of arguments to process (default: ``sys.argv[1:]``) + The input parameters are -``values`` - an :class:`optparse.Values` object to store option arguments in (default: a - new instance of :class:`Values`) -- if you give an existing object, the - option defaults will not be initialized on it + ``args`` + the list of arguments to process (default: ``sys.argv[1:]``) -and the return values are + ``values`` + an :class:`Values` object to store option arguments in (default: a + new instance of :class:`Values`) -- if you give an existing object, the + option defaults will not be initialized on it -``options`` - the same object that was passed in as ``values``, or the optparse.Values - instance created by :mod:`optparse` + and the return value is a pair ``(options, args)`` where -``args`` - the leftover positional arguments after all options have been processed + ``options`` + the same object that was passed in as *values*, or the `optparse.Values` + instance created by :mod:`optparse` + + ``args`` + the leftover positional arguments after all options have been processed The most common usage is to supply neither keyword argument. If you supply ``values``, it will be modified with repeated :func:`setattr` calls (roughly one for every option argument stored to an option destination) and returned by -:meth:`~argparse.ArgumentParser.parse_args`. +:meth:`~OptionParser.parse_args`. -If :meth:`~argparse.ArgumentParser.parse_args` encounters any errors in the argument list, it calls the +If :meth:`~OptionParser.parse_args` encounters any errors in the argument list, it calls the OptionParser's :meth:`error` method with an appropriate end-user error message. This ultimately terminates your process with an exit status of 2 (the traditional Unix exit status for command-line errors). @@ -1662,7 +1664,7 @@ where the current list of leftover arguments, ie. arguments that have been consumed but are neither options nor option arguments. Feel free to modify ``parser.largs``, e.g. by adding more arguments to it. (This list will - become ``args``, the second return value of :meth:`~argparse.ArgumentParser.parse_args`.) + become ``args``, the second return value of :meth:`~OptionParser.parse_args`.) ``parser.rargs`` the current list of remaining arguments, ie. with ``opt_str`` and From 054e3c3a8d2d641ea2f9f2f24375cf8cce4d4d11 Mon Sep 17 00:00:00 2001 From: Yuki Date: Wed, 28 Jun 2023 06:10:55 +0000 Subject: [PATCH 4/4] fixup --- Doc/library/optparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index 50ebeb6f3cb362..0cff3817452364 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -1358,7 +1358,7 @@ The whole point of creating and populating an OptionParser is to call its and the return value is a pair ``(options, args)`` where ``options`` - the same object that was passed in as *values*, or the `optparse.Values` + the same object that was passed in as *values*, or the ``optparse.Values`` instance created by :mod:`optparse` ``args``