@@ -722,8 +722,9 @@ The :meth:`~ArgumentParser.add_argument` method must know whether an optional
722722argument, like ``-f `` or ``--foo ``, or a positional argument, like a list of
723723filenames, is expected. The first arguments passed to
724724:meth: `~ArgumentParser.add_argument ` must therefore be either a series of
725- flags, or a simple argument name. For example, an optional argument could
726- be created like::
725+ flags, or a simple argument name.
726+
727+ For example, an optional argument could be created like::
727728
728729 >>> parser.add_argument('-f', '--foo')
729730
@@ -765,8 +766,9 @@ how the command-line arguments should be handled. The supplied actions are:
765766 Namespace(foo='1')
766767
767768* ``'store_const' `` - This stores the value specified by the const _ keyword
768- argument. The ``'store_const' `` action is most commonly used with
769- optional arguments that specify some sort of flag. For example::
769+ argument; note that the const _ keyword argument defaults to ``None ``. The
770+ ``'store_const' `` action is most commonly used with optional arguments that
771+ specify some sort of flag. For example::
770772
771773 >>> parser = argparse.ArgumentParser()
772774 >>> parser.add_argument('--foo', action='store_const', const=42)
@@ -795,8 +797,8 @@ how the command-line arguments should be handled. The supplied actions are:
795797 Namespace(foo=['1', '2'])
796798
797799* ``'append_const' `` - This stores a list, and appends the value specified by
798- the const _ keyword argument to the list. (Note that the const _ keyword
799- argument defaults to ``None ``.) The ``'append_const' `` action is typically
800+ the const _ keyword argument to the list; note that the const _ keyword
801+ argument defaults to ``None ``. The ``'append_const' `` action is typically
800802 useful when multiple arguments need to store constants to the same list. For
801803 example::
802804
@@ -979,17 +981,20 @@ the various :class:`ArgumentParser` actions. The two most common uses of it are
979981 ``action='store_const' `` or ``action='append_const' ``. These actions add the
980982 ``const `` value to one of the attributes of the object returned by
981983 :meth: `~ArgumentParser.parse_args `. See the action _ description for examples.
984+ If ``const `` is not provided to :meth: `~ArgumentParser.add_argument `, it will
985+ receive a default value of ``None ``.
986+
982987
983988* When :meth: `~ArgumentParser.add_argument ` is called with option strings
984989 (like ``-f `` or ``--foo ``) and ``nargs='?' ``. This creates an optional
985990 argument that can be followed by zero or one command-line arguments.
986991 When parsing the command line, if the option string is encountered with no
987- command-line argument following it, the value of ``const `` will be assumed instead.
988- See the nargs _ description for examples.
989-
990- With the ``'store_const' `` and ``'append_const' `` actions, the ``const ``
991- keyword argument must be given. For other actions, it defaults to ``None ``.
992+ command-line argument following it, the value of ``const `` will be assumed to
993+ be ``None `` instead. See the nargs _ description for examples.
992994
995+ .. versionchanged :: 3.11
996+ ``const=None `` by default, including when ``action='append_const' `` or
997+ ``action='store_const' ``.
993998
994999default
9951000^^^^^^^
0 commit comments