Mismatch between py zip() and _.zip() #42

Merged
merged 1 commit into from Jan 21, 2013

Conversation

Projects
None yet
2 participants
Contributor

hpaulj commented Jan 21, 2013

In parse_known_args() consume_positionals()
the_.zip(positionals, argCounts)
behaves different from the python version when there aren't as many
argCounts as positionals. Python zip iterates over the shortest, the
underscore version over the longest, adding undefines as needed.

The if (argCounts.length>0) takes care of some cases, but parsing
'X -f A Y', where arguments are -f, x, and y, is another case where
this JS zip is wrong. At the start, there are 2 possible positional
actions [x, y], but only one [X] argument string.

Adding an argCount === undefined test is the simplest fix.
An alternative is to define a _zipShortest() as suggested in
http://stackoverflow.com/questions/4856717/javascript-equivalent-of-pythons-zip-function/13618399#13618399

I added a test case to base.js

I discovered this case when adapting TestArgumentsFromFile from test_argparse.py

@hpaulj hpaulj Mismatch between py zip() and _.zip()
In parse_known_args() consume_positionals()
the _.zip(positionals, argCounts)
behaves different from the python version when there aren't as many
argCounts as positionals.  Python zip iterates over the shortest, the
underscore version over the longest, adding undefines as needed.

The if (argCounts.length>0) takes care of some cases, but parsing
'X -f A Y', where arguments are -a, x, and y, is another case where
this JS zip is wrong.  At the start, there are 2 possible positional
actions [x, y], but only one [X] argument string.

Adding an argCount === undefined test is the simplest fix.
An alternative is to define a _zipShortest() as suggested in
http://stackoverflow.com/questions/4856717/javascript-equivalent-of-pythons-zip-function/13618399#13618399

I added a test case to base.js

I discovered this case when adapting 'TestArgumentsFromFile' from test_argparse.py
93dee3b

@puzrin puzrin added a commit that referenced this pull request Jan 21, 2013

@puzrin puzrin Merge pull request #42 from hpaulj/corrected_zip
Mismatch between py zip() and _.zip()
403a8bb

@puzrin puzrin merged commit 403a8bb into nodeca:master Jan 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment