Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Sep 9, 2025

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


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

… 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
Copy link
Member Author

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

Copy link
Member

@savannahostrowski savannahostrowski left a 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 🙂

@serhiy-storchaka
Copy link
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.

@serhiy-storchaka
Copy link
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.)

@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
@bedevere-bot
Copy link

⚠️⚠️⚠️ 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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants