bewest / argparse

Home Page:http://docs.python.org/dev/library/argparse.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug when setting a float value to -10. and not -10.0

londumas opened this issue · comments

The bugs is due to self._negative_number_matcher

change:
self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$')

by

self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$|^-\d*\.')

test with:
import argparse as ap
p = ap.ArgumentParser()
p.add_argument("-x", type=float, required=True)
options = p.parse_args()
print(options)