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: Undeprecate getopt and optparse by serhiy-storchaka · Pull Request #126186 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 30, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

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

  • Issue: Undeprecate getopt and optparse #126180

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Oct 30, 2024
@serhiy-storchaka
serhiy-storchaka requested a review from ncoghlan October 30, 2024 15:02
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 30, 2024
willingc
willingc reviewed Oct 30, 2024
View reviewed changes

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

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 This looks good. Thanks for the detailed comments too.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/library/getopt.rst Resolved

Uh oh!

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

Comment thread Doc/whatsnew/3.13.rst
Check membership in :data:`~dis.hasarg` instead.
(Contributed by Irit Katriel in :gh:`109319`.)

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

@willingc willingc Oct 30, 2024

Copy link
Copy Markdown
Contributor

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.

Do we typically remove from the What's New for the version introduced or do we annotate that it is being changed in 3.14?

Sorry, something went wrong.

Uh oh!

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

All reactions

@serhiy-storchaka serhiy-storchaka Oct 30, 2024

Copy link
Copy Markdown
Member 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.

This is an interesting question. Obviously undeprecation should be retroactive. There is no sense in discouraging the use of getopt and optparse in 3.12 and 3.13. For 3.13, this may even be considered a bugfix.

But how to indicate this in What's New? If say nothing, then users will continue to think that getopt and optparse are deprecated. If write about this in 3.12 and 3.13, most users will not read this. So we should write something in 3.14, even if this change will be applied to 3.12 and 3.13.

Sorry, something went wrong.

Uh oh!

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

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

@willingc willingc Oct 30, 2024

Copy link
Copy Markdown
Contributor

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 don't have a good answer to this. Perhaps @hugovk would like to weigh in as release manager.

Sorry, something went wrong.

Uh oh!

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

All reactions

@hugovk hugovk Oct 30, 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.

@Yhg1s is the 3.13 RM so punting to him :)

However, optparse was deprecated back in 3.2, some 13 years ago, so for one of them, this isn't a sudden change in 3.13.

If we do undeprecate, perhaps adding a note to the existing "What's New in 3.13" entry to note it's future change?

In any case, I would also hold off merging this and allow some more time for the discussion, it's not yet been 24 hours:

https://discuss.python.org/t/getopt-and-optparse-vs-argparse/69618

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka and willingc reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@ncoghlan ncoghlan Oct 31, 2024

Copy link
Copy Markdown
Contributor

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.

In drafting my PR, I took the view that 3.13 is new enough that most of the people who will read the What's New haven't actually read it yet, and hence just changed this to a regular 3.13 What's New entry for optparse (getopt is reverting to the 3.12 status quo, so it only got mentioned in NEWS).

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka
pythongh-126180: Undeprecate the optparse and getopt modules
097cba2
@serhiy-storchaka
serhiy-storchaka force-pushed the undeprecate-getopt-optparse branch from 507bdfc to 097cba2 Compare October 30, 2024 15:16
@picnixz picnixz changed the title Undeprecate getopt and optparse gh-126180: Undeprecate getopt and optparse Oct 30, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Oct 30, 2024
Undeprecate getopt and optparse #126180
Closed
@serhiy-storchaka @willingc
Update Doc/library/getopt.rst
9744ded
Co-authored-by: Carol Willing <[email protected]>
willingc
willingc approved these changes Oct 30, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 30, 2024
@serhiy-storchaka
serhiy-storchaka requested a review from hugovk October 30, 2024 16:46
@zware zware mentioned this pull request Oct 31, 2024
Revisit getopt and optparse soft deprecations #126225
Closed
vadmium
vadmium reviewed Oct 31, 2024
View reviewed changes
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 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.

serhiy-storchaka and others added 3 commits October 31, 2024 07:34
@serhiy-storchaka @vadmium
Update Doc/library/getopt.rst
8f211ff
Co-authored-by: Martin Panter <[email protected]>
@serhiy-storchaka @vadmium
Update Doc/library/argparse.rst
22b8a77
Co-authored-by: Martin Panter <[email protected]>
@serhiy-storchaka @vadmium
Update Doc/library/argparse.rst
2c2f48f
Co-authored-by: Martin Panter <[email protected]>
@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

I missed that @serhiy-storchaka had already started on a PR for this, so #126227 is an alternative take on the same change which goes a bit further than this one does in some respects, but not as far in others:

  • retains a stronger use argparse default position to avoid triggering analysis paralysis in beginners. Yes, argparse has genuine problems (which Serhiy has been valiantly attempting to resolve), but most people won't hit them, and if they do click is often going to be a better answer than raw optparse.
  • keeps the initial note in the getopt docs
  • adds an initial note to the optparse docs that goes into exactly where argparse runs into problems
  • adds "See Also" links for click and Typer to the optparse docs (I left them out of the argparse docs due to the analysis paralysis concern)
  • splits out a new "Command Line Implementation Libraries" chapter in the docs, with these 3 modules, getpass, and curses (I was tempted to move fileinput as well, but ended up leaving it alone and eventually gave in to that temptation)
  • Changes the 3.13 What's New to explicitly note the optparse undeprecation. I still dropped any mention of getopt at all, since this is a reversion to the 3.12 status quo where that module is concerned.

I like some of the other changes Serhiy has included here, so I'm going to include them to the other PR with a Co-Authored-By note.

I've also added the DO-NOT-MERGE label to both PRs, as I agree with @hugovk that we want to let the discussion on this play out for a while longer yet.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ncoghlan ncoghlan added the DO-NOT-MERGE label Oct 31, 2024
ncoghlan
ncoghlan reviewed Oct 31, 2024
View reviewed changes

@ncoghlan ncoghlan left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

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'm definitely in favour of the general idea, but had drafted my own PR before I saw the notification that Serhiy had started this one. I prefer the overall structure of my PR (it splits out a new docs chapter for "Command Line Interface Libraries"), so I added several of Serhiy's content changes as Co-Authored-By additions over there, rather than suggesting my structural changes here.

Sorry, something went wrong.

Uh oh!

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

All reactions
@willingc

willingc commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

@serhiy-storchaka Are you cool with @ncoghlan's approach or do you want to work together to refine either one of the existing PRs?

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Oct 31, 2024

Copy link
Copy Markdown
Member Author

I am fine with either option, but I think that optparse should not be downplayed. For now, it is the safest option for beginners. argparse is too risky.

All reactions

Sorry, something went wrong.

Uh oh!

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

@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

@serhiy-storchaka Perhaps we can separate the two concerns? I think there's a piece the two of us agree on, and a piece where we still disagree (at least for now):

  • (the bit I think at least the two of us agree on) the documented deprecations of getopt and optparse should be reverted, and replaced with guidance on times when optparse is unequivocally the better option (because argparse doesn't work properly for those use cases)
  • (the still controversial bit) the default argparse recommendation should be dropped entirely because there are some signature definitions that argparse will mishandle

There are lots of CLIs where the problem of argparse mishandling leading - characters (and any similar issues) simply won't come up, because those kinds of names don't occur in practice (e.g. very few people using leading underscores in file names, so if your only options with value parameters accept file names, it probably doesn't matter to you that argparse handles them strangely).

While there are places where it might make sense for people to use optparse directly, I think it's limited to the following:

  • the solution must be in the standard library (if that isn't the case, use click or Typer instead)
  • the solution must handle leading - with the more standard conventions implemented by optparse rather than the quirky behaviours exhibited by argparse

We've spent ~15 years of telling people to use argparse over optparse, and the GitHub code search results suggest that by and large people have either been happy with that recommendation, or else sought out third party solutions like click.

It might be reasonable to include those third party recommendations in the argparse docs (in addition to having them in the optparse docs), but I don't think we'd be genuinely helping people by directing them to the lower level optparse API unless they already knew what they were doing.

Edit: Serhiy clarified on the other PR that my assumption that mishandling leading - characters was the only problematic argparse quirk is incorrect. That does strengthen Serhiy's point that the underlying problem with argparse is that when it fails, it can often be because it is behaving unreasonably, not because it is being asked to do something unreasonable, leading beginners to think they're the ones at fault, when the problem is really with argparse's behaviour being quirky.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Nov 4, 2024

Copy link
Copy Markdown
Member Author

Closing this in favor of @ncoghlan's #126227, although I disagree with continuing to recommend argparse even if we know about its flaws which were not fixed in past 15 years.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka serhiy-storchaka closed this Nov 4, 2024
@ncoghlan ncoghlan mentioned this pull request Dec 17, 2024
gh-126180: Remove getopt and optparse deprecation notices #126227
Merged
@serhiy-storchaka
serhiy-storchaka deleted the undeprecate-getopt-optparse branch July 1, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vadmium vadmium vadmium left review comments
@ncoghlan ncoghlan ncoghlan left review comments
@willingc willingc willingc approved these changes
@hugovk hugovk Awaiting requested review from hugovk

Uh oh!

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

Assignees

No one assigned

Labels

awaiting merge DO-NOT-MERGE needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

5 participants

@serhiy-storchaka @ncoghlan @willingc @vadmium @hugovk
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.