Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove getopt and optparse deprecation notices
  • Loading branch information
ncoghlan committed Oct 31, 2024
commit a560986a7f8cb3c0095bfb77d04d4cbaad0e2034
5 changes: 0 additions & 5 deletions Doc/library/allos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ but they are available on most other systems as well. Here's an overview:
os.rst
io.rst
time.rst
argparse.rst
logging.rst
logging.config.rst
logging.handlers.rst
getpass.rst
curses.rst
curses.ascii.rst
curses.panel.rst
platform.rst
errno.rst
ctypes.rst
8 changes: 8 additions & 0 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

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

.. note::

While :mod:`argparse` is the recommended standard library module for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not recommend it for now. You can use it on your own risk. optparse may need more work, but it works as expected. I would recommend it for beginners, which cannot distinguish their own errors from peculiarities of the library.

Copy link
Copy Markdown
Contributor Author

@ncoghlan ncoghlan Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR, I'd like to stick with the status quo as far as recommendations go (that is, only taking the step back from "argparse is the only non-deprecated argument processing option in the standard library").

Taking the extra step to saying "argparse is not recommended over optparse anymore, even for end user applications" would then be a separate follow up question.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Keep the argparse recommendation. We're not going to dis-recommend the most widely used Python argument parsing library in the world (that causes churn and angst from users). Nor are we going to be adding yet another one to the stdlib in the future. argparse supports most users quite well, "warts" and all, with plenty of popular third party options for yet other behaviors beyond our stdlib options.

*implementing* command line applications, authors of third party
command line argument processing libraries may find that the
simpler :mod:`optparse` module serves as a better foundation for
that use case.

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

.. sidebar:: Tutorial
Expand Down
19 changes: 19 additions & 0 deletions Doc/library/cmdlinelibs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _cmdlinelibs:

**************************************
Command Line Implementation Libraries
**************************************

The modules described in this chapter provide interfaces that assist with
implementing command line applications. Here's an overview:

.. toctree::
:maxdepth: 1

argparse.rst
optparse.rst
Comment thread
gpshead marked this conversation as resolved.
getopt.rst
getpass.rst
curses.rst
curses.ascii.rst
curses.panel.rst
5 changes: 0 additions & 5 deletions Doc/library/getopt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

**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::
Comment thread
gpshead marked this conversation as resolved.

The :mod:`getopt` module is a parser for command line options whose API is
Expand Down
1 change: 1 addition & 0 deletions Doc/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ the `Python Package Index <https://pypi.org>`_.
fileformats.rst
crypto.rst
allos.rst
cmdlinelibs.rst
concurrency.rst
ipc.rst
netdata.rst
Expand Down
36 changes: 32 additions & 4 deletions Doc/library/optparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,38 @@

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

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

:mod:`argparse` (rather than this module) is the recommended standard
library module for implementing command line applications unless one
of the following caveats applies:

* the application requires additional control over the way options and
positional parameters are interleaved on the command line (including
the ability to disable the interleaving feature completely)
* the application requires additional control over the incremental parsing
of command line elements (while ``argparse`` does support this, the
exact way it will work in practice is sometimes unpredictable)
* the application requires additional control over the handling of options
which accept parameter values that may start with ``-`` (such as delegated
options to be passed to invoked subprocesses).

These ``argparse`` caveats also mean that :mod:`optparse` is likely to
provide a better foundation for library authors *writing* third party
command line argument processing libraries.

.. seealso::

The :pypi:`"click" package <click>` is an ``optparse`` based third party
argument processing library which allows command line applications to be
developed as a set of appropriately decorated command implementation
functions.

.. seealso::

The :pypi:`"Typer" package <click>` is a ``click`` based third party
argument processing library which allows the use of annotated Python
type hints to define an application's command line interface.
Comment thread
ncoghlan marked this conversation as resolved.
Outdated

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

Expand Down
8 changes: 2 additions & 6 deletions Doc/library/superseded.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,5 @@ Superseded Modules
The modules described in this chapter are deprecated or :term:`soft deprecated` and only kept for
backwards compatibility. They have been superseded by other modules.


.. toctree::
:maxdepth: 1

getopt.rst
optparse.rst
With the removal of various obsolete modules through :pep:`594`, there are currently no modules
in this category.
20 changes: 12 additions & 8 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,18 @@ opcode
(Contributed by Irit Katriel in :gh:`105481`.)


optparse
--------

* This module is no longer considered :term:`soft deprecated`.
While :mod:`argparse` remains preferred for new projects that
aren't using a third party command line argument processing
library, there are aspects of the way ``argparse`` works that
means ``optparse`` may provide a better foundation for *writing*
argument processing libraries.
(Contributed by Alyssa Coghlan in :gh:`126225`.)


pathlib
-------

Expand Down Expand Up @@ -1787,14 +1799,6 @@ New Deprecations
Check membership in :data:`~dis.hasarg` instead.
(Contributed by Irit Katriel in :gh:`109319`.)

* :mod:`getopt` and :mod:`optparse`:

* Both modules are now :term:`soft deprecated`,
with :mod:`argparse` preferred for new projects.
This is a new soft-deprecation for the :mod:`!getopt` module,
whereas the :mod:`!optparse` module was already *de facto* soft deprecated.
(Contributed by Victor Stinner in :gh:`106535`.)

* :mod:`gettext`:

* Deprecate non-integer numbers as arguments to functions and methods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:mod:`getopt` and :mod:`optparse` are no longer marked as deprecated.
There are legitimate reasons to use one of these modules in preference to
:mod:`argparse`, and none of these modules are at risk of being removed
from the standard library. Of the three, ``argparse`` remains the
recommended default choice, *unless* one of the concerns noted at the top of
the module documentation applies.