From 1cfa51b3bf19f82cb97e09393cc346acaee6ba93 Mon Sep 17 00:00:00 2001 From: jdunter <2ve@mailbox.org> Date: Sat, 19 Jul 2025 13:52:32 +0200 Subject: [PATCH 1/4] gh-54732: Make argparse error caused by empty rows explicit --- Doc/library/argparse.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index f189f6b8fa8953..f07a7d8a4333d6 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -440,6 +440,12 @@ were in the same place as the original file referencing argument on the command line. So in the example above, the expression ``['-f', 'foo', '@args.txt']`` is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. +.. note:: + + Empty lines are treated as empty strings (''), which are allowed as values but not + as arguments. Empty lines as arguments will result in an “unrecognized arguments” + error. + :class:`ArgumentParser` uses :term:`filesystem encoding and error handler` to read the file containing arguments. From d2f76e41b3de3103b419e7254f4fbcb42683bfc4 Mon Sep 17 00:00:00 2001 From: jdunter <2ve@mailbox.org> Date: Sat, 19 Jul 2025 14:44:12 +0200 Subject: [PATCH 2/4] gh-54732: Address suggestions from PR Discussion. Namely the use of code markup. Also I fixed a trailing whitespace. --- Doc/library/argparse.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index f07a7d8a4333d6..059503a601e341 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -442,8 +442,8 @@ is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. .. note:: - Empty lines are treated as empty strings (''), which are allowed as values but not - as arguments. Empty lines as arguments will result in an “unrecognized arguments” + Empty lines are treated as empty strings (``''``), which are allowed as values but not + as arguments. Empty lines as arguments will result in an “unrecognized arguments” error. :class:`ArgumentParser` uses :term:`filesystem encoding and error handler` From ea5188712423188929ce11c1f2f707c1389613d5 Mon Sep 17 00:00:00 2001 From: jdunter <2ve@mailbox.org> Date: Sat, 19 Jul 2025 15:54:17 +0200 Subject: [PATCH 3/4] gh-54732: Address suggestions from real life PR Discussion. Change two of the phrasings to make it more clear. Use straight quotes. --- Doc/library/argparse.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 059503a601e341..502f69a59d9a64 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -434,7 +434,7 @@ arguments they contain. For example:: >>> parser.parse_args(['-f', 'foo', '@args.txt']) Namespace(f='bar') -Arguments read from a file must by default be one per line (but see also +Arguments read from a file must be one per line by default (but see also :meth:`~ArgumentParser.convert_arg_line_to_args`) and are treated as if they were in the same place as the original file referencing argument on the command line. So in the example above, the expression ``['-f', 'foo', '@args.txt']`` @@ -442,9 +442,9 @@ is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. .. note:: - Empty lines are treated as empty strings (``''``), which are allowed as values but not - as arguments. Empty lines as arguments will result in an “unrecognized arguments” - error. + Empty lines are treated as empty strings (``''``), which are allowed as values but + not as arguments. Empty lines, that are read as arguments will result in an + "unrecognized arguments" error. :class:`ArgumentParser` uses :term:`filesystem encoding and error handler` to read the file containing arguments. From b74413d230ed2a3fe1304e89aaf78b567ebbc382 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 19 Jul 2025 15:02:40 +0100 Subject: [PATCH 4/4] Update Doc/library/argparse.rst --- Doc/library/argparse.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 502f69a59d9a64..a08f713ab56ba3 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -443,7 +443,7 @@ is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. .. note:: Empty lines are treated as empty strings (``''``), which are allowed as values but - not as arguments. Empty lines, that are read as arguments will result in an + not as arguments. Empty lines that are read as arguments will result in an "unrecognized arguments" error. :class:`ArgumentParser` uses :term:`filesystem encoding and error handler`