From 073eb3422df391e1ae0cd2c6d75b3c9568bc3d5b Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Fri, 16 May 2025 21:57:37 +0100 Subject: [PATCH] Fix --- Lib/argparse.py | 2 ++ Lib/test/test_argparse.py | 2 ++ .../next/Library/2025-05-16-21-54-00.gh-issue-54732.asfjdf.rst | 1 + 3 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-05-16-21-54-00.gh-issue-54732.asfjdf.rst diff --git a/Lib/argparse.py b/Lib/argparse.py index f688c38d0d1ae5..a05ee4396891cc 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2363,6 +2363,8 @@ def _read_args_from_files(self, arg_strings): errors=_sys.getfilesystemencodeerrors()) as args_file: arg_strings = [] for arg_line in args_file.read().splitlines(): + if not arg_line.strip(): + continue for arg in self.convert_arg_line_to_args(arg_line): arg_strings.append(arg) arg_strings = self._read_args_from_files(arg_strings) diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 58853ba4eb3674..c120775d8a5ea3 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -1715,6 +1715,7 @@ def setUp(self): b'@hello'), ('invalid', b'@no-such-path\n'), ('undecodable', self.undecodable + b'\n'), + ('blanklines', b'spam\n\nham\n') ] for path, text in file_texts: with open(path, 'wb') as file: @@ -1736,6 +1737,7 @@ def setUp(self): ('-a B @recursive Y Z', NS(a='A', x=hello, y=['Y', 'Z'])), ('X @recursive Z -a B', NS(a='B', x='X', y=[hello, 'Z'])), (["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])), + ('@blanklines', NS(a=None, x='spam', y=['ham'])), ] if os_helper.TESTFN_UNDECODABLE: undecodable = os_helper.TESTFN_UNDECODABLE.lstrip(b'@') diff --git a/Misc/NEWS.d/next/Library/2025-05-16-21-54-00.gh-issue-54732.asfjdf.rst b/Misc/NEWS.d/next/Library/2025-05-16-21-54-00.gh-issue-54732.asfjdf.rst new file mode 100644 index 00000000000000..d1bb8481a95331 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-16-21-54-00.gh-issue-54732.asfjdf.rst @@ -0,0 +1 @@ +Fix issue in :mod:`argparse` where an args file with blank lines could not be parsed. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy