Giter VIP home page Giter VIP logo

Comments (5)

hpaulj avatar hpaulj commented on June 24, 2024

I submitted a patch to Python issue 9334 to

  • accept negative scientific and complex numbers
  • add the args_default_to_positional parser option

http://bugs.python.org/issue9334#msg184987

from argparse.

puzrin avatar puzrin commented on June 24, 2024

@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.

from argparse.

hpaulj avatar hpaulj commented on June 24, 2024

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 _negativeNumberMatcher.

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:

 if not self._has_negative_number_optionals:
     try:
         complex(arg_string)
         return None
 except ValueError:
        pass

The javascript equivalent could use !isNaN(argString)

if (!_.any(this._hasNegativeNumberOptionals) && !isNaN(argString)) {
  return null;
}

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.

from argparse.

puzrin avatar puzrin commented on June 24, 2024

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% :) .

from argparse.

rlidwka avatar rlidwka commented on June 24, 2024

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.

from argparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.