Skip to content

gh-136032: Fix argparse.BooleanOptionalAction doc #136133

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -839,15 +839,17 @@ how the command-line arguments should be handled. The supplied actions are:
>>> parser.parse_args(['--version'])
PROG 2.0

Only actions that consume command-line arguments (e.g. ``'store'``,
``'append'`` or ``'extend'``) can be used with positional arguments.
Note that only actions that consume command-line arguments (e.g. ``'store'``,
``'append'`` or ``'extend'``) can be used with positional arguments. You may
also specify an arbitrary action by passing an :class:`Action` subclass or
other object that implements the same interface.

.. class:: BooleanOptionalAction

You may also specify an arbitrary action by passing an :class:`Action` subclass or
other object that implements the same interface. The :class:`!BooleanOptionalAction`
is available in :mod:`!argparse` and adds support for boolean actions such as
``--foo`` and ``--no-foo``::
A subclass of :class:`Action` for handling boolean flags with positive
and negative options. Adding a single argument such as ``--foo`` automatically
creates both ``--foo`` and ``--no-foo`` options, storing ``True`` and ``False``
respectively::

>>> import argparse
>>> parser = argparse.ArgumentParser()
Expand Down
Loading