summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-12-02 13:50:48 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-12-02 13:50:48 (GMT)
commitb55c4d4539dfaa4f085fcd08d9779b217ba411a9 (patch)
tree96decb1069d0b8de1729faff73f42dee2d8af134 /Doc
parent10a8e6ab7b913370672b1d8e0aadf0b34ef1c143 (diff)
parentf3114532e4a59fff647f2edb777351b3a4839095 (diff)
downloadcpython-b55c4d4539dfaa4f085fcd08d9779b217ba411a9.zip
cpython-b55c4d4539dfaa4f085fcd08d9779b217ba411a9.tar.gz
cpython-b55c4d4539dfaa4f085fcd08d9779b217ba411a9.tar.bz2
Issue #19814: Clarify argparse's docs w.r.t prefix matching
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/argparse.rst14
1 files changed, 11 insertions, 3 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 5b7d016..51abc7a 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1371,12 +1371,14 @@ argument::
>>> parser.parse_args(['--', '-f'])
Namespace(foo='-f', one=None)
+.. _prefix-matching:
-Argument abbreviations
-^^^^^^^^^^^^^^^^^^^^^^
+Argument abbreviations (prefix matching)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The :meth:`~ArgumentParser.parse_args` method allows long options to be
-abbreviated if the abbreviation is unambiguous::
+abbreviated to a prefix, if the abbreviation is unambiguous (the prefix matches
+a unique option)::
>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-bacon')
@@ -1854,6 +1856,12 @@ the populated namespace and the list of remaining argument strings.
>>> parser.parse_known_args(['--foo', '--badger', 'BAR', 'spam'])
(Namespace(bar='BAR', foo=True), ['--badger', 'spam'])
+.. warning::
+ :ref:`Prefix matching <prefix-matching>` rules apply to
+ :meth:`parse_known_args`. The parser may consume an option even if it's just
+ a prefix of one of its known options, instead of leaving it in the remaining
+ arguments list.
+
Customizing file parsing
^^^^^^^^^^^^^^^^^^^^^^^^