Skip to content

Commit

Permalink
GH-127134: Add note about forward compatibility for suggest_on_error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
savannahostrowski authored Nov 23, 2024
1 parent 39e60ae commit a13e94d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ are strings::
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')

If you're writing code that needs to be compatible with older Python versions
and want to opportunistically use ``suggest_on_error`` when it's available, you
can set it as an attribute after initializing the parser instead of using the
keyword argument::

>>> parser = argparse.ArgumentParser(description='Process some integers.')
>>> parser.suggest_on_error = True

.. versionadded:: 3.14


Expand Down

0 comments on commit a13e94d

Please sign in to comment.