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-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction by serhiy-storchaka · Pull Request #138692 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 9, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.

  • Issue: argparse.BooleanOptionalAction silently failed when used with parser whose prefix_chars has no '-' #138525

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

Sorry, something went wrong.

Uh oh!

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

mattwang44 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@serhiy-storchaka
serhiy-storchaka requested a review from savannahostrowski September 9, 2025 07:41
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner September 9, 2025 07:41
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 9, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 9, 2025
argparse.BooleanOptionalAction silently failed when used with parser whose prefix_chars has no '-' #138525
Closed
@serhiy-storchaka
serhiy-storchaka force-pushed the BooleanOptionalAction-prefix_chars branch from fe05304 to bd8247f Compare September 9, 2025 10:13
@serhiy-storchaka serhiy-storchaka mentioned this pull request Sep 9, 2025
argparse: long options with mixed prefix characters #138701
Open
@serhiy-storchaka
pythongh-138525: Support single-dash long options and prefix_chars in…
4fa348b
… BooleanOptionalAction

-no-foo is generated for -foo.
++no-foo is generated for ++foo.
/no-foo is generated for /foo.
@serhiy-storchaka
serhiy-storchaka force-pushed the BooleanOptionalAction-prefix_chars branch from bd8247f to 4fa348b Compare September 9, 2025 11:23
serhiy-storchaka added 3 commits November 18, 2025 19:03
@serhiy-storchaka
Merge branch 'main' into BooleanOptionalAction-prefix_chars
0006cbc
@serhiy-storchaka
Merge branch 'main' into BooleanOptionalAction-prefix_chars
56efe05
@serhiy-storchaka
Use the "no" prefix instead of "no-" for single-dash options.
4c95f91
@serhiy-storchaka

serhiy-storchaka commented Nov 21, 2025

Copy link
Copy Markdown
Member Author

It seems that programs that use single-dash long options does not usually have a hyphen after "no".

All reactions

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka added 2 commits November 21, 2025 10:58
@serhiy-storchaka
Merge branch 'main' into BooleanOptionalAction-prefix_chars
74edc92
@serhiy-storchaka
Add comments.
69c08e7
savannahostrowski
savannahostrowski approved these changes Nov 22, 2025
View reviewed changes

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

Overall, the implementation here looks good. I've tested it pretty extensively and everything works as expected. We might want to add a test the verifies that single-character options don't get negation variants created (e.g. -n shouldn't get -non).

On a process-related note, I noticed that #138526 was opened earlier for the referenced issue. It might be good to collaborate on existing PRs and/or give this feedback to the contributor (or even ask them if they'd like to try out adding the feature you have in mind). The more robust fix to add this feature isn't too complicated for someone newer to argparse. Might have been a good opportunity to get another active contributor in the module 🙂

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Nov 22, 2025
@serhiy-storchaka

serhiy-storchaka commented Nov 22, 2025

Copy link
Copy Markdown
Member Author

We might want to add a test the verifies that single-character options don't get negation variants created (e.g. -n shouldn't get -non).

This is tested, see the '-nox' case in failures for '-x'.

On a process-related note, I noticed that #138526 was opened earlier for the referenced issue.

I opened this PR after seen that PR. As I said in the review, I do not think that approach is correct.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
Merge branch 'main' into BooleanOptionalAction-prefix_chars
1c0726f
@serhiy-storchaka

serhiy-storchaka commented Nov 22, 2025

Copy link
Copy Markdown
Member Author

(My objection was to the initial version of #138526, not to the current one. But this PR supersedes it without a need to extend the Action interface with a private method.)

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) November 22, 2025 20:39
@serhiy-storchaka
serhiy-storchaka merged commit 425fd85 into python:main Nov 22, 2025
46 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 22, 2025
@serhiy-storchaka serhiy-storchaka mentioned this pull request Nov 22, 2025
gh-138525: raise error when BooleanOptionalAction used with prefix_chars without '-' #138526
Closed
@bedevere-bot

bedevere-bot commented Nov 22, 2025

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 CentOS9 NoGIL Refleaks 3.x (tier-1) has failed when building commit 425fd85.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1610/builds/2463) and take a look at the build logs.
  4. Check if the failure is related to this commit (425fd85) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1610/builds/2463

Failed tests:

  • test_free_threading

Test leaking resources:

  • test_free_threading: file descriptors

Summary of the results of the build (if available):

==

Click to see traceback logs
remote: Enumerating objects: 16, done.        
remote: Counting objects:   6% (1/15)        
remote: Counting objects:  13% (2/15)        
remote: Counting objects:  20% (3/15)        
remote: Counting objects:  26% (4/15)        
remote: Counting objects:  33% (5/15)        
remote: Counting objects:  40% (6/15)        
remote: Counting objects:  46% (7/15)        
remote: Counting objects:  53% (8/15)        
remote: Counting objects:  60% (9/15)        
remote: Counting objects:  66% (10/15)        
remote: Counting objects:  73% (11/15)        
remote: Counting objects:  80% (12/15)        
remote: Counting objects:  86% (13/15)        
remote: Counting objects:  93% (14/15)        
remote: Counting objects: 100% (15/15)        
remote: Counting objects: 100% (15/15), done.        
remote: Compressing objects:  33% (1/3)        
remote: Compressing objects:  66% (2/3)        
remote: Compressing objects: 100% (3/3)        
remote: Compressing objects: 100% (3/3), done.        
remote: Total 16 (delta 12), reused 13 (delta 12), pack-reused 1 (from 1)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '425fd85ca360a39a1a3fb16f09c448cb93ff794a'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 425fd85ca36 gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction (GH-138692)
Switched to and reset branch 'main'

configure: WARNING: no system libmpdec found; falling back to pure-Python version for the decimal module

make: *** [Makefile:2493: buildbottest] Error 2
All reactions

Sorry, something went wrong.

Uh oh!

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

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@serhiy-storchaka @StanFromIreland
pythongh-138525: Support single-dash long options and prefix_chars in…
076e529
… BooleanOptionalAction (pythonGH-138692)

-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
@serhiy-storchaka @ashm-dev
pythongh-138525: Support single-dash long options and prefix_chars in…
4edec83
… BooleanOptionalAction (pythonGH-138692)

-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.
@serhiy-storchaka
serhiy-storchaka deleted the BooleanOptionalAction-prefix_chars branch July 1, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@savannahostrowski savannahostrowski savannahostrowski approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

3 participants

@serhiy-storchaka @bedevere-bot @savannahostrowski
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.