@@ -844,21 +844,6 @@ Only actions that consume command-line arguments (e.g. ``'store'``,
844
844
also specify an arbitrary action by passing an :class: `Action ` subclass or
845
845
other object that implements the same interface.
846
846
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
-
862
847
The recommended way to create a custom action is to extend :class: `Action `,
863
848
overriding the :meth: `!__call__ ` method and optionally the :meth: `!__init__ ` and
864
849
: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
1431
1416
and return a string which will be used when printing the usage of the program.
1432
1417
If such method is not provided, a sensible default will be used.
1433
1418
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
1434
1433
1435
1434
The parse_args() method
1436
1435
-----------------------
0 commit comments