-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure to recognize negative scientific notation (with nargs:2) #55
Comments
I submitted a patch to Python issue 9334 to
|
@hpaulj negative sentific floats now works. This fix does not cover complex numbers and values with leading dashes. I think, this can be safely postponed, until someone really needs it in real life. |
I explored expanding the regex expression like this. Adding the exponential is easy. Adding complex makes the whole expression unwieldy. In the Python patch I chose instead to separate the two uses of For identifying negative like option strings I left the original matcher (examples are all simple ones like '-1', not even '-1.23', much less '-1.23e4'.) For identifying real negative numbers, I chose instead to let Python's own number parser do the job:
The javascript equivalent could use
But since javascript does not have complex number type, expanding the regex to include exponentials should be just fine. I've submitted a number of python argparse patches, but haven't gotten much feedback from their developers. |
Yes, isNaN would be more simple. I didn't digged into algorythm, and just replaced existing regexp, after trebor89 pointed to bad line of code :) . By the way, may be you have time to look into mincer project https://github.com/nodeca/mincer ? It has much more space for improvements, than argparse. I think, even in current state, argparse cover node developer's needs for 200% :) . |
Argparse 2.0 was ported from scratch based on python 3.9.0. We aimed to keep source code as close as possible to the original, so this change didn't make it in. Is it used by anybody? If so, maybe bug python developers again, issue still not resolved over there. |
On stackoverflow I came across an argparse.py issue that also affects this version. It has to do with recognizing negative numbers like
-2e4
. ThenegativeNumberMatcher
does not handle scientific notation.However the issue only rises in special circumstances such as a
nargs:2
case, and there are work arounds.http://stackoverflow.com/questions/9025204/python-argparse-issue-with-optional-arguments-which-are-negative-numbers
http://bugs.python.org/issue9334
may be a related issue (parsing
['-a','-one','-two']
where(['-a',{nargs:2})
. That is, should '-one' be interpreted as an optional, or as an argument to '-a'?The text was updated successfully, but these errors were encountered: