Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'@')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue in :mod:`argparse` where an args file with blank lines could not be parsed.
Loading