Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRITICAL: getattr() does not have 3rd argument #633

Open
faerot opened this issue May 11, 2019 · 4 comments
Open

CRITICAL: getattr() does not have 3rd argument #633

faerot opened this issue May 11, 2019 · 4 comments
Assignees

Comments

@faerot
Copy link

faerot commented May 11, 2019

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.

@AlexECX
Copy link

AlexECX commented May 12, 2019

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

@faerot
Copy link
Author

faerot commented Jul 6, 2019

}else if (failsafe) {
this should probably be
}else if (failsafe !== undefined) {
as we can pass False, empty string or None as default values

@JdeH
Copy link
Collaborator

JdeH commented Aug 14, 2019

There's no good reason why this is left out.
It will be added in the next minor version.
Thanks for the suggestion!

@JdeH JdeH self-assigned this Aug 14, 2019
@phfaist
Copy link

phfaist commented Jul 12, 2022

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!

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

No branches or pull requests

4 participants