Skip to content

Commit 18f51f9

Browse files
authored
gh-101100: Fix reference to parse_args in optparse.rst (#105265)
1 parent d830c4a commit 18f51f9

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

Doc/library/optparse.rst

+27-24
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ on the command-line, for example::
4242
<yourscript> --file=outfile -q
4343

4444
As it parses the command line, :mod:`optparse` sets attributes of the
45-
``options`` object returned by :meth:`parse_args` based on user-supplied
46-
command-line values. When :meth:`parse_args` returns from parsing this command
45+
``options`` object returned by :meth:`~OptionParser.parse_args` based on user-supplied
46+
command-line values. When :meth:`~OptionParser.parse_args` returns from parsing this command
4747
line, ``options.filename`` will be ``"outfile"`` and ``options.verbose`` will be
4848
``False``. :mod:`optparse` supports both long and short options, allows short
4949
options to be merged together, and allows options to be associated with their
@@ -285,10 +285,10 @@ program's command line::
285285

286286
(options, args) = parser.parse_args()
287287

288-
(If you like, you can pass a custom argument list to :meth:`parse_args`, but
288+
(If you like, you can pass a custom argument list to :meth:`~OptionParser.parse_args`, but
289289
that's rarely necessary: by default it uses ``sys.argv[1:]``.)
290290

291-
:meth:`parse_args` returns two values:
291+
:meth:`~OptionParser.parse_args` returns two values:
292292

293293
* ``options``, an object containing values for all of your options---e.g. if
294294
``--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::
339339

340340
When :mod:`optparse` sees the option string ``-f``, it consumes the next
341341
argument, ``foo.txt``, and stores it in ``options.filename``. So, after this
342-
call to :meth:`parse_args`, ``options.filename`` is ``"foo.txt"``.
342+
call to :meth:`~OptionParser.parse_args`, ``options.filename`` is ``"foo.txt"``.
343343

344344
Some other option types supported by :mod:`optparse` are ``int`` and ``float``.
345345
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
453453
value supplied for any particular destination is the one that counts.
454454

455455
A clearer way to specify default values is the :meth:`set_defaults` method of
456-
OptionParser, which you can call at any time before calling :meth:`parse_args`::
456+
OptionParser, which you can call at any time before calling
457+
:meth:`~OptionParser.parse_args`::
457458

458459
parser.set_defaults(verbose=True)
459460
parser.add_option(...)
@@ -1338,35 +1339,37 @@ Parsing arguments
13381339
^^^^^^^^^^^^^^^^^
13391340

13401341
The whole point of creating and populating an OptionParser is to call its
1341-
:meth:`parse_args` method::
1342+
:meth:`~OptionParser.parse_args` method.
13421343

1343-
(options, args) = parser.parse_args(args=None, values=None)
1344+
.. method:: OptionParser.parse_args(args=None, values=None)
13441345

1345-
where the input parameters are
1346+
Parse the command-line options found in *args*.
13461347

1347-
``args``
1348-
the list of arguments to process (default: ``sys.argv[1:]``)
1348+
The input parameters are
13491349

1350-
``values``
1351-
an :class:`optparse.Values` object to store option arguments in (default: a
1352-
new instance of :class:`Values`) -- if you give an existing object, the
1353-
option defaults will not be initialized on it
1350+
``args``
1351+
the list of arguments to process (default: ``sys.argv[1:]``)
13541352

1355-
and the return values are
1353+
``values``
1354+
an :class:`Values` object to store option arguments in (default: a
1355+
new instance of :class:`Values`) -- if you give an existing object, the
1356+
option defaults will not be initialized on it
13561357

1357-
``options``
1358-
the same object that was passed in as ``values``, or the optparse.Values
1359-
instance created by :mod:`optparse`
1358+
and the return value is a pair ``(options, args)`` where
13601359

1361-
``args``
1362-
the leftover positional arguments after all options have been processed
1360+
``options``
1361+
the same object that was passed in as *values*, or the ``optparse.Values``
1362+
instance created by :mod:`optparse`
1363+
1364+
``args``
1365+
the leftover positional arguments after all options have been processed
13631366

13641367
The most common usage is to supply neither keyword argument. If you supply
13651368
``values``, it will be modified with repeated :func:`setattr` calls (roughly one
13661369
for every option argument stored to an option destination) and returned by
1367-
:meth:`parse_args`.
1370+
:meth:`~OptionParser.parse_args`.
13681371

1369-
If :meth:`parse_args` encounters any errors in the argument list, it calls the
1372+
If :meth:`~OptionParser.parse_args` encounters any errors in the argument list, it calls the
13701373
OptionParser's :meth:`error` method with an appropriate end-user error message.
13711374
This ultimately terminates your process with an exit status of 2 (the
13721375
traditional Unix exit status for command-line errors).
@@ -1661,7 +1664,7 @@ where
16611664
the current list of leftover arguments, ie. arguments that have been
16621665
consumed but are neither options nor option arguments. Feel free to modify
16631666
``parser.largs``, e.g. by adding more arguments to it. (This list will
1664-
become ``args``, the second return value of :meth:`parse_args`.)
1667+
become ``args``, the second return value of :meth:`~OptionParser.parse_args`.)
16651668

16661669
``parser.rargs``
16671670
the current list of remaining arguments, ie. with ``opt_str`` and

0 commit comments

Comments
 (0)