From 01998c80014d43f18c8f5dc3ec774adb211e0c07 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 16 Nov 2024 16:56:22 -0800 Subject: [PATCH 1/2] Clarify parse_known_args --- Doc/library/argparse.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 7638798ca2552f..f9c1bd7e8b7ed8 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2059,14 +2059,15 @@ Partial parsing .. method:: ArgumentParser.parse_known_args(args=None, namespace=None) - Sometimes a script may only parse a few of the command-line arguments, passing - the remaining arguments on to another script or program. In these cases, the - :meth:`~ArgumentParser.parse_known_args` method can be useful. It works much like - :meth:`~ArgumentParser.parse_args` except that it does not produce an error when - extra arguments are present. Instead, it returns a two item tuple containing - the populated namespace and the list of remaining argument strings. - - :: + Sometimes a script only needs to handle a specific set of command-line + arguments, leaving any unrecognized arguments for another script or program. + In these cases, the :meth:`~ArgumentParser.parse_known_args` method can be + useful. + + This method works similarly to :meth:`~ArgumentParser.parse_args`, but it does + not raise an error for extra, unrecognized arguments. Instead, it parses the + known arguments and returns a two item tuple that contains the populated + namespace and the list of any unrecognized arguments:: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_true') From 0059151f5fba568448a91bbc4c24ab52caaa6039 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 16 Nov 2024 17:02:19 -0800 Subject: [PATCH 2/2] Add period back --- Doc/library/argparse.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index f9c1bd7e8b7ed8..51ed29a2a0795d 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -2067,7 +2067,9 @@ Partial parsing This method works similarly to :meth:`~ArgumentParser.parse_args`, but it does not raise an error for extra, unrecognized arguments. Instead, it parses the known arguments and returns a two item tuple that contains the populated - namespace and the list of any unrecognized arguments:: + namespace and the list of any unrecognized arguments. + + :: >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--foo', action='store_true')