Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a13e94d

Browse files
GH-127134: Add note about forward compatibility for suggest_on_error (#127137)
1 parent 39e60ae commit a13e94d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/argparse.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ are strings::
589589
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
590590
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
591591

592+
If you're writing code that needs to be compatible with older Python versions
593+
and want to opportunistically use ``suggest_on_error`` when it's available, you
594+
can set it as an attribute after initializing the parser instead of using the
595+
keyword argument::
596+
597+
>>> parser = argparse.ArgumentParser(description='Process some integers.')
598+
>>> parser.suggest_on_error = True
599+
592600
.. versionadded:: 3.14
593601

594602

0 commit comments

Comments
 (0)