gh-138525: Support single-dash long options and prefix_chars in BooleanOptionalAction (GH-138692)

-nofoo is generated for -foo.
++no-foo is generated for ++foo.
/nofoo is generated for /foo.
This commit is contained in:
Serhiy Storchaka 2025-11-22 22:54:02 +02:00 committed by GitHub
parent cde19e565c
commit 425fd85ca3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 102 additions and 4 deletions

View file

@ -1445,8 +1445,18 @@ this API may be passed as the ``action`` parameter to
>>> parser.parse_args(['--no-foo'])
Namespace(foo=False)
Single-dash long options are also supported.
For example, negative option ``-nofoo`` is automatically added for
positive option ``-foo``.
But no additional options are added for short options such as ``-f``.
.. versionadded:: 3.9
.. versionchanged:: next
Added support for single-dash options.
Added support for alternate prefix_chars_.
The parse_args() method
-----------------------