← Back to DAGDA | Support | Source: https://bugs.python.org/issue25475

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: use argparse instead of getopt
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, matrixise, r.david.murray
Priority: normal Keywords:

Created on 2015-10-25 17:16 by matrixise, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg253429 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2015-10-25 17:16
not sure, but in the documentation, there is a note
"Module argparse: Alternative command line option and argument parsing library."

may be it's time to move from getopt to argparse and mark getopt as deprecated.

We have to modify 45 files, but I can submit a separated patch for each file.

ack "import getopt" -l | wc -l
      45
msg253430 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-10-25 17:29
This seems like a change for the sake of change. I think any module that requires argparse features can be moved in its own time.
msg253431 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2015-10-25 17:37
it's not for the pleasure, but there are two api for the command line. getopt and argparse. so in this case, what's the reason to keep both ? in particular if the documentation of getopt has a note with an alternative.

maybe to keep the backward compatibility, but in this case, maybe we can start to deprecate getopt in favour of argparse.
msg253432 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2015-10-25 17:39
and optparse.

In fact, we have getopt, optparse and argparse. 3 API for the command line.

optparse is marked as deprecated.
maybe we can add getopt in this list.
msg253433 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-10-25 19:10
This was discussed when argparse was included in the standard library, and the conclusion was that getopt serves a different purpose than argparse and should not be deprecated.  argparse is mentioned as an alternative since in many cases it is to be preferred, but there are cases where getopt is the better choice.  (I myself have a command line parsing library (not yet published) that uses getopt as its base.)

As far as using argparse in the standard library, yes, we convert modules on a case by case basis when someone has the interest and the time to write tests for the existing command line behavior before doing the conversion.  And in every case we have still introduced bugs when the conversion was released, so this should not be done lightly (ie: we usually only do it when introducing new functionality or fixing a bug).
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69661
2015-10-25 19:10:56r.david.murraysetnosy: + r.david.murray

messages: + msg253433
stage: resolved
2015-10-25 17:39:26matrixisesetmessages: + msg253432
2015-10-25 17:37:16matrixisesetmessages: + msg253431
2015-10-25 17:29:30SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg253430

resolution: rejected
2015-10-25 17:16:29matrixisecreate