Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-126180: Remove getopt and optparse deprecation notices#126227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

ncoghlan
Copy link
Contributor

@ncoghlanncoghlan commentedOct 31, 2024
edited
Loading

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.


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

@ncoghlanncoghlan changed the titlegh-126225: Remove getopt and optparse deprecation noticesgh-126180: Remove getopt and optparse deprecation noticesOct 31, 2024
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a 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 inargparse, but there are many others. The difference is fundamental in the way how optional and positional arguments are parsed.

@@ -11,6 +11,18 @@

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

.. note::

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

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.

scastlara reacted with confused emoji
Copy link
ContributorAuthor

@ncoghlanncoghlanOct 31, 2024
edited
Loading

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 isnot recommended overoptparse anymore, even for end user applications" would then be a separate follow up question.

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

ncoghlan reacted with thumbs up emoji
@ncoghlan
Copy link
ContributorAuthor

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

@ncoghlan
Copy link
ContributorAuthor

@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

@ncoghlan
Copy link
ContributorAuthor

@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.


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

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.

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 theargparse module documentation. Thegetopt module documentation is not the place where users will search information about theargparse module.

gpshead reacted with thumbs up emoji
Copy link
Member

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).

Copy link
ContributorAuthor

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 theoptparse 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 theargparse docs shorter, and added a link to this new section.

@ncoghlan
Copy link
ContributorAuthor

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).

@ncoghlan
Copy link
ContributorAuthor

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.

@ncoghlan
Copy link
ContributorAuthor

@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!).

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

ncoghlan reacted with heart emoji
@gpshead
Copy link
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, vsargparse) - the point of this PRto me is to remove the loaded term "deprecated" on the old ones because we're never going toremove them. We just want to guide users toargparse by default and point at the others as also available for specific needs. Betweensys.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'tencourage outsiders to contribute new features togetopt oroptparsemyself. 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.

@ncoghlanncoghlan merged commit831b6de intopython:mainDec 23, 2024
31 of 33 checks passed
@ncoghlanncoghlan deleted the reverse-getopt-optparse-deprecations branchDecember 23, 2024 04:17
@ncoghlan
Copy link
ContributorAuthor

Done! Thanks for the reviews, folks.

@ncoghlanncoghlan added the needs backport to 3.13bugs and security fixes labelDec 23, 2024
@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestDec 23, 2024
…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 commit831b6de)Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

GH-128191 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelDec 23, 2024
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestDec 23, 2024
…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 <storchaka@gmail.com>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 8, 2025
…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 <storchaka@gmail.com>
aaronliu0130 added a commit to aaronliu0130/pylint that referenced this pull requestFeb 1, 2025
Upstream undeprecated it in December (python/cpython#126227)
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this pull requestFeb 1, 2025
Upstream undeprecated it in December (python/cpython#126227)
github-actionsbot pushed a commit to pylint-dev/pylint that referenced this pull requestFeb 1, 2025
Upstream undeprecated it in December (python/cpython#126227)(cherry picked from commit47579c8)
aaronliu0130 added a commit to aaronliu0130/pylint that referenced this pull requestFeb 1, 2025
Upstream undeprecated it in December (python/cpython#126227)
jacobtylerwalls pushed a commit to pylint-dev/pylint that referenced this pull requestFeb 1, 2025
Upstream undeprecated it in December (python/cpython#126227)(cherry picked from commit47579c8)Co-authored-by: Aaron Liu <aaronliu0130@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@merwokmerwokmerwok left review comments

@mwichmannmwichmannmwichmann left review comments

@LilyAcornLilyAcornLilyAcorn left review comments

@gpsheadgpsheadgpshead approved these changes

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@savannahostrowskisavannahostrowskiAwaiting requested review from savannahostrowskisavannahostrowski is a code owner

Assignees
No one assigned
Labels
docsDocumentation in the Doc dir
Projects
Status: Done
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Undeprecate getopt and optparse
6 participants
@ncoghlan@serhiy-storchaka@gpshead@merwok@mwichmann@LilyAcorn

[8]ページ先頭

©2009-2025 Movatter.jp