coppinri · GitHub

Bug report

Bug description:

Simple example:

$ python test_arguments.py --Value -1_000.0
error: argument -v/--Value: expected one argument

The regular expression to identify negative numbers in the argparse.py module uses the following regular expression:

#argparse.py:1353-1354
        # determines whether an "option" looks like a negative number
        self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$')

This does not identify negative numerical values with underscores as a numerical value

This could probably be resolved by changing the regex to:

        # determines whether an "option" looks like a negative number
        self._negative_number_matcher = _re.compile(r'^-\d[\d_]*$|^-[\d_]*\.\d+$')

CPython versions tested on:

3.9

Operating systems tested on:

Windows

Linked PRs

Read the original on github.com ↗