Transcrypt
Transcrypt copied to clipboard
CRITICAL: getattr() does not have 3rd argument
I was surprised that getattr() function does not allow third default argument, which is critically important basic functionality as JavaScript does not raise AttributeErrors when accessing missing attributes and we cannot rely on those.
Funny, I was reminded of it while working on #630 as it was messing with my tests. I've been working with this in the meantime:
boost_transcript.js
export var getattr = function (obj, name, failsafe) {
if (name in obj) {
return obj [name];
} else if (obj ['py_' + name]) {
return obj ['py_' + name];
} else if (failsafe !== undefined) {
return failsafe;
} else {
var __except0__ = AttributeError ('object has no attribute ' + name);
__except0__.__cause__ = null;
throw __except0__;
}
};
If whe can't have getattr throw an exception (but why?), then removing the last else will make the function return undefined as usual
}else if (failsafe) {
this should probably be
}else if (failsafe !== undefined) {
as we can pass False, empty string or None as default values
There's no good reason why this is left out. It will be added in the next minor version. Thanks for the suggestion!
Hi! I ran across the same issue recently (with Transcrypt 3.9.0 from pypi). Is there anything holding back the associated pull request #727? Thanks!