gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction by serhiy-storchaka · Pull Request #138692 · python/cpython · GitHub
Skip to content

gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction#138692

Merged
serhiy-storchaka merged 7 commits into
python:mainfrom
serhiy-storchaka:BooleanOptionalAction-prefix_chars
Nov 22, 2025
Merged

gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction#138692
serhiy-storchaka merged 7 commits into
python:mainfrom
serhiy-storchaka:BooleanOptionalAction-prefix_chars

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

-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
Copy Markdown
Member Author

@savannahostrowski savannahostrowski left a comment

Copy link
Copy Markdown
Member

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

@serhiy-storchaka

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

@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
Copy Markdown

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
… 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
… BooleanOptionalAction (pythonGH-138692)

-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.
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