GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-126180: Remove getopt and optparse deprecation notices by ncoghlan · Pull Request #126227 · python/cpython

Conversation

@ncoghlan

@ncoghlan ncoghlan commented Oct 31, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

getopt and optparse are in no way at risk of being removed,
as they have genuinely valid use cases. Those use cases
(mimicing the C getopt API, implementing third party
command line argument processing libraries) are just
far less common than the ones that argparse addresses.

Closes #126180.

  • Issue: Undeprecate getopt and optparse #126180

📚 Documentation preview 📚: https://cpython-previews--126227.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ncoghlan
Remove getopt and optparse deprecation notices
a560986
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir awaiting core review labels Oct 31, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Oct 31, 2024
Revisit getopt and optparse soft deprecations #126225
Closed
@ncoghlan
Wording tweaks
0a568f1
@ncoghlan ncoghlan changed the title gh-126225: Remove getopt and optparse deprecation notices gh-126180: Remove getopt and optparse deprecation notices Oct 31, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Oct 31, 2024
Undeprecate getopt and optparse #126180
Closed
@ncoghlan ncoghlan added the DO-NOT-MERGE label Oct 31, 2024
@ncoghlan ncoghlan mentioned this pull request Oct 31, 2024
gh-126180: Undeprecate getopt and optparse #126186
Closed
ncoghlan and others added 9 commits October 31, 2024 16:14
@ncoghlan @serhiy-storchaka
Incorporate improvements from Serhiy's PR
55b7215
Co-authored-by: Serhiy Storchaka <[email protected]>
@ncoghlan
Grammar fix
0971780
@ncoghlan
Fix issue number reference
09b0237
@ncoghlan
Another wording tweak
4cdebde
@ncoghlan
Update heading and description for new chapter
693a979
@ncoghlan
fileinput belongs in the new chapter
50d1ee4
@ncoghlan
Move getopt back to the superseded section
4e50c74
@ncoghlan
Reword superseded chapter intro
0db2c88
@ncoghlan
Simplify wording
e474e77
ncoghlan
ncoghlan commented Oct 31, 2024
View reviewed changes
Comment thread Doc/library/optparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka
serhiy-storchaka self-requested a review October 31, 2024 08:50
serhiy-storchaka
serhiy-storchaka reviewed Oct 31, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You are focused on one particular peculiarity in argparse, but there are many others. The difference is fundamental in the way how optional and positional arguments are parsed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/howto/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/argparse.rst Outdated

.. note::

While :mod:`argparse` is the recommended standard library module for

@serhiy-storchaka serhiy-storchaka Oct 31, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

scastlara reacted with confused emoji
All reactions
  • 😕 1 reaction

@ncoghlan ncoghlan Oct 31, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gpshead gpshead Nov 8, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Doc/library/cmdlinelibs.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/getopt.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/getopt.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/getopt.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/getopt.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Oct 31, 2024

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka I think several of your suggestions are good improvements. I should have time to incorporate them tomorrow (Nov 1 AEST)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

LilyFirefly
LilyFirefly reviewed Oct 31, 2024
View reviewed changes
Comment thread Doc/library/optparse.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Nov 1, 2024

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka I won't get back to this today, and this weekend isn't looking good either. Early next week will probably be the next update.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan added 2 commits November 2, 2024 17:47
@ncoghlan
Merge remote-tracking branch 'origin/main' into reverse-getopt-optpar…
43234de
…se-deprecations
@ncoghlan
Updates based on Serhiy's feedback
93d7161
@ncoghlan

ncoghlan commented Nov 2, 2024

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka I ended up procrastinating on my assignment by working on this (amongst other things), so I've pushed some updates for you to take a look at when you're back at work.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan added 2 commits November 2, 2024 23:04
@ncoghlan
Also reword What's New entry
bb91b52
@ncoghlan
Consistent getopt markup
7cc72ad
ncoghlan
ncoghlan commented Nov 2, 2024
View reviewed changes
Comment thread Doc/library/getopt.rst Outdated

Whether these differing behaviors in the ``argparse`` version are
considered desirable or a problem will depend on the specific command line
application use case.

@ncoghlan ncoghlan Nov 2, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@serhiy-storchaka ^^^ is the main reason I don't think we should walk back the default argparse recommendation. Many (probably even most) Python devs would consider argparse to be in the right for these 3 examples, and getopt/optparse the ones doing something dubious (even if what they're doing is the common Unix convention).

The discrepancies are valid reasons for reverting the soft deprecation (optparse can genuinely be used to define command line behaviours that argparse doesn't support), but it will take less arguable examples than these ones to make the case that optparse should be preferred over argparse in general.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@serhiy-storchaka serhiy-storchaka Nov 4, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It would be better to write about these peculiarities in the argparse module documentation. The getopt module documentation is not the place where users will search information about the argparse module.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@gpshead gpshead Nov 8, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

agreed. I like that we're giving a list of differences in behavior, but I think it makes more sense to put this in a common section :ref:'d from all three of our command line parsing module docs. I don't expect anyone reading argparse (most likely) or optparse (likely) docs to find this in the getopt docs (presumed least likely to be read).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Dec 8, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I've moved this to a new "Choosing an argument parsing library" section at the start of the optparse docs. getopt still has the example code, but refers to that new section to explain the differences.

Similar, I made the note at the start of the argparse docs shorter, and added a link to this new section.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ncoghlan

ncoghlan commented Dec 17, 2024

Copy link
Copy Markdown
Contributor Author

I forgot I had marked this as draft when it was clear it was going to take me a while to get back to it. Belatedly switched it back to ready for review after the last round of updates (this is the full version of the patch - once I made time for it, I made enough time for that rather than pursuing the interim change discussed above).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan ncoghlan removed the DO-NOT-MERGE label Dec 17, 2024
@ncoghlan

ncoghlan commented Dec 17, 2024

Copy link
Copy Markdown
Contributor Author

The DO-NOT-MERGE label was a mutual one with #126186 until we decided which of the PRs to use as the basis for docs updates. With #126186 closed, that means this one can be handled via the regular PR review process.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead
gpshead approved these changes Dec 17, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 17, 2024
@ncoghlan

ncoghlan commented Dec 18, 2024

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka Let me know if you want to take another look before I merge this, otherwise I'll merge it early next week (a Christmas present for happy optparse and getopt users!).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka
serhiy-storchaka approved these changes Dec 18, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@gpshead

gpshead commented Dec 18, 2024

Copy link
Copy Markdown
Member

From my perspective this is ready to go in. I didn't immediately click merge as I wanted to let others speak up if they believe otherwise. Edited quoting of myself from Discord:

"""
It's not like there is any big official "plan" (re: getopt, optparse, vs argparse) - the point of this PR to me is to remove the loaded term "deprecated" on the old ones because we're never going to remove them. We just want to guide users to argparse by default and point at the others as also available for specific needs. Between sys.argv, these three modules, and everything on PyPI I'm sure we have 14 ways to do command line parsing that are all wrong from someones perspective anyways.
I wouldn't encourage outsiders to contribute new features to getopt or optparse myself. But if a core dev is willing to review them and guarantee backwards compatibility with tests, go for it.
""" - me

Feel free to merge when you're ready.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan
ncoghlan merged commit 831b6de into python:main Dec 23, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 23, 2024
@ncoghlan
ncoghlan deleted the reverse-getopt-optparse-deprecations branch December 23, 2024 04:17
@ncoghlan

ncoghlan commented Dec 23, 2024

Copy link
Copy Markdown
Contributor Author

Done! Thanks for the reviews, folks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan ncoghlan added the needs backport to 3.13 only security fixes label Dec 23, 2024
@miss-islington-app

miss-islington-app Bot commented Dec 23, 2024

Copy link
Copy Markdown

Thanks @ncoghlan for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 23, 2024
@ncoghlan @serhiy-storchaka @miss-islington
pythongh-126180: Remove getopt and optparse deprecation notices (pyth…
efec8a8
…onGH-126227)

* Remove getopt and optparse deprecation notices
* Add new docs sections for command line app helper libraries
* Add guidance on choosing a CLI parsing library to the optparse docs
* Link to the new guidance from the argparse and getopt docs
* Reword intro in docs section for superseded stdlib modules
* Reframe the optparse->argparse guide as a migration guide
  rather than as an upgrade guide

---------
(cherry picked from commit 831b6de)

Co-authored-by: Alyssa Coghlan <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-app

bedevere-app Bot commented Dec 23, 2024

Copy link
Copy Markdown

GH-128191 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Dec 23, 2024
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Dec 23, 2024
@ncoghlan @serhiy-storchaka @srinivasreddy
pythongh-126180: Remove getopt and optparse deprecation notices (pyth…
b7bfacb
…onGH-126227)

* Remove getopt and optparse deprecation notices
* Add new docs sections for command line app helper libraries
* Add guidance on choosing a CLI parsing library to the optparse docs
* Link to the new guidance from the argparse and getopt docs
* Reword intro in docs section for superseded stdlib modules
* Reframe the optparse->argparse guide as a migration guide
  rather than as an upgrade guide

---------

Co-authored-by: Serhiy Storchaka <[email protected]>
@stefanor stefanor mentioned this pull request Dec 30, 2024
Replace Deprecated optparse with argparse for Command-Line Parsing pwaller/pyfiglet#142
Closed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@ncoghlan @serhiy-storchaka @srinivasreddy
pythongh-126180: Remove getopt and optparse deprecation notices (pyth…
4444c03
…onGH-126227)

* Remove getopt and optparse deprecation notices
* Add new docs sections for command line app helper libraries
* Add guidance on choosing a CLI parsing library to the optparse docs
* Link to the new guidance from the argparse and getopt docs
* Reword intro in docs section for superseded stdlib modules
* Reframe the optparse->argparse guide as a migration guide
  rather than as an upgrade guide

---------

Co-authored-by: Serhiy Storchaka <[email protected]>
@savannahostrowski savannahostrowski mentioned this pull request Jan 31, 2025
Undo deprecation of optparse #81284
Closed
@jacobtylerwalls jacobtylerwalls mentioned this pull request Feb 1, 2025
getopt doesn't seem deprecated pylint-dev/pylint#10211
Closed
aaronliu0130 added a commit to aaronliu0130/pylint that referenced this pull request Feb 1, 2025
@aaronliu0130
undeprecate getopt
8855d73
Upstream undeprecated it in December (python/cpython#126227)
@aaronliu0130 aaronliu0130 mentioned this pull request Feb 1, 2025
Undeprecate getopt pylint-dev/pylint#10213
Merged
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this pull request Feb 1, 2025
@aaronliu0130
Undeprecate getopt (#10213)
47579c8
Upstream undeprecated it in December (python/cpython#126227)
github-actions Bot pushed a commit to pylint-dev/pylint that referenced this pull request Feb 1, 2025
@aaronliu0130 @github-actions
Undeprecate getopt (#10213)
8c2f2d6
Upstream undeprecated it in December (python/cpython#126227)

(cherry picked from commit 47579c8)
aaronliu0130 added a commit to aaronliu0130/pylint that referenced this pull request Feb 1, 2025
@aaronliu0130
also undeprecate optparse
02bebc6
Upstream undeprecated it in December (python/cpython#126227)
@aaronliu0130 aaronliu0130 mentioned this pull request Feb 1, 2025
Also undeprecate optparse pylint-dev/pylint#10215
Merged
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this pull request Feb 1, 2025
@github-actions @aaronliu0130
Undeprecate getopt (#10213) (#10214)
a3f9b7c
Upstream undeprecated it in December (python/cpython#126227)

(cherry picked from commit 47579c8)

Co-authored-by: Aaron Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merwok merwok merwok left review comments
@gpshead gpshead gpshead approved these changes
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski savannahostrowski is a code owner
+2 more reviewers
@mwichmann mwichmann mwichmann left review comments
@LilyFirefly LilyFirefly LilyFirefly left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

docs Documentation in the Doc dir

Projects

Docs PRs
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Undeprecate getopt and optparse

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ncoghlan @serhiy-storchaka @gpshead @merwok @mwichmann @LilyFirefly
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.