Skip to content

Commit b708956

Browse files
committed
doc(argparse): move BooleanOptionalAction to Action classes section
1 parent 7157cd0 commit b708956

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Doc/library/argparse.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -844,21 +844,6 @@ Only actions that consume command-line arguments (e.g. ``'store'``,
844844
also specify an arbitrary action by passing an :class:`Action` subclass or
845845
other object that implements the same interface.
846846

847-
.. class:: BooleanOptionalAction
848-
849-
A subclass of :class:`Action` for handling boolean flags with positive
850-
and negative options. Adding a single argument such as ``--foo`` automatically
851-
creates both ``--foo`` and ``--no-foo`` options, storing ``True`` and ``False``
852-
respectively::
853-
854-
>>> import argparse
855-
>>> parser = argparse.ArgumentParser()
856-
>>> parser.add_argument('--foo', action=argparse.BooleanOptionalAction)
857-
>>> parser.parse_args(['--no-foo'])
858-
Namespace(foo=False)
859-
860-
.. versionadded:: 3.9
861-
862847
The recommended way to create a custom action is to extend :class:`Action`,
863848
overriding the :meth:`!__call__` method and optionally the :meth:`!__init__` and
864849
:meth:`!format_usage` methods. You can also register custom actions using the
@@ -1431,6 +1416,20 @@ this API may be passed as the ``action`` parameter to
14311416
and return a string which will be used when printing the usage of the program.
14321417
If such method is not provided, a sensible default will be used.
14331418

1419+
.. class:: BooleanOptionalAction
1420+
1421+
A subclass of :class:`Action` for handling boolean flags with positive
1422+
and negative options. Adding a single argument such as ``--foo`` automatically
1423+
creates both ``--foo`` and ``--no-foo`` options, storing ``True`` and ``False``
1424+
respectively::
1425+
1426+
>>> import argparse
1427+
>>> parser = argparse.ArgumentParser()
1428+
>>> parser.add_argument('--foo', action=argparse.BooleanOptionalAction)
1429+
>>> parser.parse_args(['--no-foo'])
1430+
Namespace(foo=False)
1431+
1432+
.. versionadded:: 3.9
14341433

14351434
The parse_args() method
14361435
-----------------------

0 commit comments

Comments
 (0)