Skip to content

Commit

Permalink
Version that works
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-migdal committed Oct 25, 2023
1 parent 7459d76 commit 4496ff3
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions www/src/py_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ function args0_NEW(fct, args) {
const PARAMS_POSONLY_COUNT = $CODE.co_posonlyargcount;
const PARAMS_POS_DEFAULTS_MAXID = PARAMS_POS_DEFAULTS_COUNT + PARAMS_POS_DEFAULTS_OFFSET;

const PARAMS_NAMED_DEFAULTS = Object.values(kwargs_defaults); //TODO: precompute this plz
const PARAMS_NAMED_DEFAULTS_OFFSET = PARAMS_NAMES.length - PARAMS_NAMED_DEFAULTS.length;

if( offset < PARAMS_POSONLY_COUNT ) {

if( offset < PARAMS_POS_DEFAULTS_OFFSET ) {
Expand Down Expand Up @@ -304,22 +301,18 @@ function args0_NEW(fct, args) {
result[key] = PARAMS_POS_DEFAULTS[ioffset - PARAMS_POS_DEFAULTS_OFFSET];
++found;
}
for( ; ioffset < PARAMS_NAMED_DEFAULTS_OFFSET; ++ioffset) {

const key = PARAMS_NAMES[ioffset];
if( key in result ) // maybe could be speed up using "!(key in result)"
continue;

args0(fct, args);
throw new Error('Missing a named arguments (args0 should have raised an error) !');
}
for( ; ioffset < PARAMS_NAMES.length; ++ioffset) {

const key = PARAMS_NAMES[ioffset];
if( key in result )
continue;

result[key] = PARAMS_NAMED_DEFAULTS[ioffset - PARAMS_NAMED_DEFAULTS_OFFSET]; // should be quicker
if( ! (key in kwargs_defaults) ) {
args0(fct, args);
throw new Error('Missing a named arguments (args0 should have raised an error) !');
}

result[key] = kwargs_defaults[key];
++found;
}

Expand Down Expand Up @@ -389,22 +382,19 @@ function args0_NEW(fct, args) {
result[key] = PARAMS_POS_DEFAULTS[ioffset - PARAMS_POS_DEFAULTS_OFFSET];
++found;
}
for( ; ioffset < PARAMS_NAMED_DEFAULTS_OFFSET; ++ioffset) {

const key = PARAMS_NAMES[ioffset];
if( key in result ) // maybe could be speed up using "!(key in result)"
continue;

args0(fct, args);
throw new Error('Missing a named arguments (args0 should have raised an error) !');
}
for( ; ioffset < PARAMS_NAMES.length; ++ioffset) {

const key = PARAMS_NAMES[ioffset];
if( key in result )
continue;
result[key] = PARAMS_NAMED_DEFAULTS[ioffset - PARAMS_NAMED_DEFAULTS_OFFSET]; // should be quicker
++found;

if( ! (key in kwargs_defaults) ) {
args0(fct, args);
throw new Error('Missing a named arguments (args0 should have raised an error) !');
}

result[key] = kwargs_defaults[key];
++found;
}

// Same as "No **kwargs parameter".
Expand Down

0 comments on commit 4496ff3

Please sign in to comment.