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: Undeprecate getopt and optparse#126186

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedOct 30, 2024
edited by bedevere-appbot
Loading

Copy link
Contributor

@willingcwillingc left a 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.

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

* :mod:`getopt` and :mod:`optparse`:
Copy link
Contributor

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?

Copy link
MemberAuthor

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.

willingc reacted with thumbs up emoji
Copy link
Contributor

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.

Copy link
Member

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

serhiy-storchaka and willingc reacted with thumbs up emoji
Copy link
Contributor

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 whowill 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 foroptparse (getopt is reverting to the 3.12 status quo, so it only got mentioned in NEWS).

@picnixzpicnixz changed the titleUndeprecate getopt and optparsegh-126180: Undeprecate getopt and optparseOct 30, 2024
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Martin Panter <vadmium@users.noreply.github.com>
Co-authored-by: Martin Panter <vadmium@users.noreply.github.com>
Co-authored-by: Martin Panter <vadmium@users.noreply.github.com>
@ncoghlan
Copy link
Contributor

ncoghlan commentedOct 31, 2024
edited
Loading

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 useargparse 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 doclick is often going to be a better answer than rawoptparse.
  • keeps the initial note in thegetopt docs
  • adds an initial note to theoptparse docs that goes into exactly where argparse runs into problems
  • adds "See Also" links forclick andTyper to theoptparse docs (I left them out of theargparse docs due to the analysis paralysis concern)
  • splits out a new "Command Line Implementation Libraries" chapter in the docs, with these 3 modules,getpass, andcurses (I was tempted to movefileinput 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 theoptparse undeprecation. I still dropped any mention ofgetopt 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.

Copy link
Contributor

@ncoghlanncoghlan left a comment
edited
Loading

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

@willingc
Copy link
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?

@serhiy-storchaka
Copy link
MemberAuthor

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

@ncoghlan
Copy link
Contributor

ncoghlan commentedOct 31, 2024
edited
Loading

@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 ofgetopt andoptparse should be reverted, and replaced with guidance on times whenoptparse is unequivocally the better option (becauseargparse doesn't work properly for those use cases)
  • (the still controversial bit) the defaultargparse recommendation should be dropped entirely because there are some signature definitions thatargparse will mishandle

There arelots of CLIs where the problem ofargparse 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 thatargparse handles them strangely).

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

  • the solutionmust be in the standard library (if that isn't the case, useclick orTyper instead)
  • the solutionmust handle leading- with the more standard conventions implemented byoptparse rather than the quirky behaviours exhibited byargparse

We've spent ~15 years of telling people to useargparse overoptparse, 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 likeclick.

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

Edit: Serhiy clarified on the other PR that my assumption that mishandling leading- characters was theonly problematicargparse quirk is incorrect. That does strengthen Serhiy's point that the underlying problem withargparse 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.

@serhiy-storchaka
Copy link
MemberAuthor

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vadmiumvadmiumvadmium left review comments

@ncoghlanncoghlanncoghlan left review comments

@willingcwillingcwillingc approved these changes

@hugovkhugovkAwaiting requested review from hugovk

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@serhiy-storchaka@ncoghlan@willingc@vadmium@hugovk

[8]ページ先頭

©2009-2025 Movatter.jp