https://github.com/python/cpython/commit/a13e94d84bff334da3da2cab523ba75b57e0787f
commit: a13e94d84bff334da3da2cab523ba75b57e0787f
branch: main
author: Savannah Ostrowski <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2024-11-22T19:18:18-08:00
summary:

GH-127134: Add note about forward compatibility for suggest_on_error (#127137)

files:
M Doc/library/argparse.rst

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index e574511436d16e..410b6e11af0dc0 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -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
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to