@@ -74,7 +74,7 @@ ArgumentParser objects
7474 prefix_chars='-', fromfile_prefix_chars=None, \
7575 argument_default=None, conflict_handler='error', \
7676 add_help=True, allow_abbrev=True, exit_on_error=True, \
77- *, suggest_on_error=False , color=True)
77+ *, suggest_on_error=True , color=True)
7878
7979 Create a new :class: `ArgumentParser ` object. All parameters should be passed
8080 as keyword arguments. Each parameter has its own more detailed description
@@ -117,7 +117,7 @@ ArgumentParser objects
117117 error info when an error occurs. (default: ``True ``)
118118
119119 * suggest_on_error _ - Enables suggestions for mistyped argument choices
120- and subparser names (default: ``False ``)
120+ and subparser names (default: ``True ``)
121121
122122 * color _ - Allow color output (default: ``True ``)
123123
@@ -134,6 +134,9 @@ ArgumentParser objects
134134 .. versionchanged :: 3.14
135135 *suggest_on_error * and *color * parameters were added.
136136
137+ .. versionchanged :: 3.15
138+ *suggest_on_error * default changed to ``True ``.
139+
137140The following sections describe how each of these are used.
138141
139142
@@ -596,13 +599,11 @@ suggest_on_error
596599^^^^^^^^^^^^^^^^
597600
598601By default, when a user passes an invalid argument choice or subparser name,
599- :class: `ArgumentParser ` will exit with error info and list the permissible
600- argument choices (if specified) or subparser names as part of the error message.
601-
602- If the user would like to enable suggestions for mistyped argument choices and
603- subparser names, the feature can be enabled by setting ``suggest_on_error `` to
604- ``True ``. Note that this only applies for arguments when the choices specified
605- are strings::
602+ :class: `ArgumentParser ` will exit with error info and provide suggestions for
603+ mistyped arguments. The error message will list the permissible argument
604+ choices (if specified) or subparser names, along with a "maybe you meant"
605+ suggestion if a close match is found. Note that this only applies for arguments
606+ when the choices specified are strings::
606607
607608 >>> parser = argparse.ArgumentParser(description='Process some integers.',
608609 suggest_on_error=True)
@@ -612,16 +613,14 @@ are strings::
612613 >>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
613614 tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
614615
615- If you're writing code that needs to be compatible with older Python versions
616- and want to opportunistically use ``suggest_on_error `` when it's available, you
617- can set it as an attribute after initializing the parser instead of using the
618- keyword argument::
616+ You can disable suggestions by setting ``suggest_on_error `` to ``False ``::
619617
620- >>> parser = argparse.ArgumentParser(description='Process some integers.')
621- >>> parser.suggest_on_error = True
618+ >>> parser = argparse.ArgumentParser(description='Process some integers.',
619+ suggest_on_error=False)
622620
623621.. versionadded :: 3.14
624-
622+ .. versionchanged :: 3.15
623+ Changed default value of ``suggest_on_error `` from ``False `` to ``True ``.
625624
626625color
627626^^^^^
0 commit comments