[New-bugs-announce] [issue22672] float arguments in scientific notation not supported by argparse

Jacopo Nespolo report at bugs.python.org
Sun Oct 19 20:10:15 CEST 2014


New submission from Jacopo Nespolo:

Argparse fails to recognise negative numbers in scientific notation as valid numbers.

Example:
Suppose the program test.py has this option.
    par.add_argument('-a', type=float)

then './test.py -a -1e5' will fail, as well as -1.0e-4, -.5E+4 and variations thereof.
Furthermore, at the current state, it seems that argparse does not recognize -1. as a valid float either.

I tried to hack argparse.py myself, and I believe the patch attached should fix this issue. The base version of argparse.py is the one from Python 3.4.2 as found in Debian Sid.

The modified regular expression seemed to behave correctly in all test cases I could come up with.

----------
components: Library (Lib)
files: argparse.patch
keywords: patch
messages: 229689
nosy: jnespolo
priority: normal
severity: normal
status: open
title: float arguments in scientific notation not supported by argparse
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file36972/argparse.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22672>
_______________________________________


More information about the New-bugs-announce mailing list