]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19814: Clarify argparse's docs w.r.t prefix matching
authorEli Bendersky <eliben@gmail.com>
Mon, 2 Dec 2013 13:49:54 +0000 (05:49 -0800)
committerEli Bendersky <eliben@gmail.com>
Mon, 2 Dec 2013 13:49:54 +0000 (05:49 -0800)
Doc/library/argparse.rst

index 0b18c6d91661aeed41efe54af3e808ac67f13cb4..b686c44e4f9894f13226f0d504f73b80a0ba7944 100644 (file)
@@ -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')
@@ -1852,6 +1854,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
 ^^^^^^^^^^^^^^^^^^^^^^^^