You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There appears to be a bug in the runtime's implementation of the pop() method of dict objects. If the value in the dictionary associated with the given key happens to be None (null), then the value is not returned and it is not removed from the dictionary. I think the fix is very easy (see below).
Here's a minimal working example:
# bug.pya= { 'hello': None }
value=a.pop('hello', '<DEFAULT>')
print('value = ', value, '; a = ', a)
The outputs I get with python, and with transcrypt/node, are:
# python bug.py
value = None ; a = {}
# transcrypt bug.py --nomin ; echo '{"type":"module"}' >__target__/package.json; node __target__/bug.js
value = <DEFAULT> ; a = {'hello': None}
It appears that the incorrect behavior is the result of a comparison of the value with undefined using the != operator in the runtime's implementation of __pop__(). Correct behavior is achieved if I modify the runtime's __pop__ function in __target__/org.transcrypt.__runtime__.js as follows:
function __pop__ (aKey, aDefault) {
var result = this [aKey];
- if (result != undefined) {+ if (result !== undefined) {
delete this [aKey];
return result;
} else {
if ( aDefault === undefined ) {
throw KeyError (aKey, new Error());
}
}
return aDefault;
}
Then I obtain, correctly:
# node __target__/bug.js
value = None ; a = {}
From searching in transcrypt's code base, it would appear that the relevant line to update is this one.
The text was updated successfully, but these errors were encountered:
There appears to be a bug in the runtime's implementation of the
pop()
method ofdict
objects. If the value in the dictionary associated with the given key happens to beNone
(null
), then the value is not returned and it is not removed from the dictionary. I think the fix is very easy (see below).Here's a minimal working example:
The outputs I get with python, and with transcrypt/node, are:
It appears that the incorrect behavior is the result of a comparison of the value with undefined using the
!=
operator in the runtime's implementation of__pop__()
. Correct behavior is achieved if I modify the runtime's__pop__
function in__target__/org.transcrypt.__runtime__.js
as follows:Then I obtain, correctly:
From searching in transcrypt's code base, it would appear that the relevant line to update is this one.
The text was updated successfully, but these errors were encountered: