]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-127134: Add note about forward compatibility for suggest_on_error (#127137)
authorSavannah Ostrowski <savannahostrowski@gmail.com>
Sat, 23 Nov 2024 03:18:18 +0000 (19:18 -0800)
committerGitHub <noreply@github.com>
Sat, 23 Nov 2024 03:18:18 +0000 (19:18 -0800)
Doc/library/argparse.rst

index e574511436d16ef1d14f54ef4039609e38ef9f28..410b6e11af0dc09cd14bcf53de7b10091a2efa53 100644 (file)
@@ -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