Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4703d1

Browse files
committed
Merge #12353: argparse now correctly handles null argument values.
Patch by Torsten Landschoff.
2 parents af418b2 + b94082a commit d4703d1

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ def _read_args_from_files(self, arg_strings):
19791979
for arg_string in arg_strings:
19801980

19811981
# for regular arguments, just add them back into the list
1982-
if arg_string[0] not in self.fromfile_prefix_chars:
1982+
if not arg_string or arg_string[0] not in self.fromfile_prefix_chars:
19831983
new_arg_strings.append(arg_string)
19841984

19851985
# replace arguments referencing files with the file content

Lib/test/test_argparse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ def setUp(self):
13721372
('X @hello', NS(a=None, x='X', y=['hello world!'])),
13731373
('-a B @recursive Y Z', NS(a='A', x='hello world!', y=['Y', 'Z'])),
13741374
('X @recursive Z -a B', NS(a='B', x='X', y=['hello world!', 'Z'])),
1375+
(["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])),
13751376
]
13761377

13771378

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Core and Builtins
5252
Library
5353
-------
5454

55+
- Issue #12353: argparse now correctly handles null argument values.
56+
5557
- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
5658
user-defined types as keys or other unorderable keys.
5759

0 commit comments

Comments
 (0)