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

Skip to content

Commit b94082a

Browse files
committed
#12353: argparse now correctly handles null argument values.
Patch by Torsten Landschoff.
1 parent 15cd9a0 commit b94082a

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
@@ -1976,7 +1976,7 @@ def _read_args_from_files(self, arg_strings):
19761976
for arg_string in arg_strings:
19771977

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

19821982
# 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
@@ -1371,6 +1371,7 @@ def setUp(self):
13711371
('X @hello', NS(a=None, x='X', y=['hello world!'])),
13721372
('-a B @recursive Y Z', NS(a='A', x='hello world!', y=['Y', 'Z'])),
13731373
('X @recursive Z -a B', NS(a='B', x='X', y=['hello world!', 'Z'])),
1374+
(["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])),
13741375
]
13751376

13761377

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Core and Builtins
9898
Library
9999
-------
100100

101+
- Issue #12353: argparse now correctly handles null argument values.
102+
101103
- Issues #10017 and #14998: Fix TypeError using pprint on dictionaries with
102104
user-defined types as keys or other unorderable keys.
103105

0 commit comments

Comments
 (0)