Skip to content

Commit

Permalink
gh-106535: Soft deprecate the getopt module (#105735)
Browse files Browse the repository at this point in the history
The getopt module exists since the initial revision of the Python
source code (1990). The optparse module was added to Python 2.3. When
Python 2.7 added the 3rd argparse module, the optparse module was
soft deprecated. Soft deprecate the getopt module.
  • Loading branch information
vstinner committed Jul 8, 2023
1 parent b305c69 commit da98ed0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Doc/library/getopt.rst
Expand Up @@ -7,18 +7,23 @@

**Source code:** :source:`Lib/getopt.py`

.. deprecated:: 3.13
The :mod:`getopt` module is :term:`soft deprecated` and will not be
developed further; development will continue with the :mod:`argparse`
module.

.. note::

The :mod:`getopt` module is a parser for command line options whose API is
designed to be familiar to users of the C :c:func:`getopt` function. Users who
are unfamiliar with the C :c:func:`getopt` function or who would like to write
designed to be familiar to users of the C :c:func:`!getopt` function. Users who
are unfamiliar with the C :c:func:`!getopt` function or who would like to write
less code and get better help and error messages should consider using the
:mod:`argparse` module instead.

--------------

This module helps scripts to parse the command line arguments in ``sys.argv``.
It supports the same conventions as the Unix :c:func:`getopt` function (including
It supports the same conventions as the Unix :c:func:`!getopt` function (including
the special meanings of arguments of the form '``-``' and '``--``'). Long
options similar to those supported by GNU software may be used as well via an
optional third argument.
Expand All @@ -33,11 +38,11 @@ exception:
be parsed, without the leading reference to the running program. Typically, this
means ``sys.argv[1:]``. *shortopts* is the string of option letters that the
script wants to recognize, with options that require an argument followed by a
colon (``':'``; i.e., the same format that Unix :c:func:`getopt` uses).
colon (``':'``; i.e., the same format that Unix :c:func:`!getopt` uses).

.. note::

Unlike GNU :c:func:`getopt`, after a non-option argument, all further
Unlike GNU :c:func:`!getopt`, after a non-option argument, all further
arguments are considered also non-options. This is similar to the way
non-GNU Unix systems work.

Expand Down Expand Up @@ -71,7 +76,7 @@ exception:
non-option argument is encountered.

If the first character of the option string is ``'+'``, or if the environment
variable :envvar:`POSIXLY_CORRECT` is set, then option processing stops as
variable :envvar:`!POSIXLY_CORRECT` is set, then option processing stops as
soon as a non-option argument is encountered.


Expand All @@ -81,9 +86,9 @@ exception:
an option requiring an argument is given none. The argument to the exception is
a string indicating the cause of the error. For long options, an argument given
to an option which does not require one will also cause this exception to be
raised. The attributes :attr:`msg` and :attr:`opt` give the error message and
raised. The attributes :attr:`!msg` and :attr:`!opt` give the error message and
related option; if there is no specific option to which the exception relates,
:attr:`opt` is an empty string.
:attr:`!opt` is an empty string.

.. XXX deprecated?
.. exception:: error
Expand Down

0 comments on commit da98ed0

Please sign in to comment.