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

More flexibility when importing python modules #3

Closed
mattaustin opened this issue Oct 9, 2013 · 3 comments
Closed

More flexibility when importing python modules #3

mattaustin opened this issue Oct 9, 2013 · 3 comments

Comments

@mattaustin
Copy link

Hi, a feature request here to allow more flexibility when importing/accessing python modules.

It would be great if importModule could accept an 'as' argument for the equivalent
python:

from myapp.ui import foo as bar

I also noticed that if importing a 'nested/namespaced' python module, e.g. myapp.ui.foo, then I can't use functions from it. It doesn't show an import error, but the functions aren't available when using call.

For example myapp.api.foo.get_station_list won't work, but if I import the namespaced module with addImportPath('myapp/api') then foo.get_station_list does work.

@wrobell
Copy link

wrobell commented Feb 4, 2014

I can confirm the issue with importing packages, i.e. a.b.c - the import does not fail, but calling a function from a.b.c fails with::

[F] qt_assert:2014 - ASSERT: "list != NULL" in file qpython_priv.cpp, line 194
Aborted

@thp thp closed this as completed in 28d5e92 Feb 8, 2014
@thp
Copy link
Owner

thp commented Feb 8, 2014

This has now been fixed with commit 28d5e92. In PyOtherSide 1.0 and 1.1, the behavior of importModule was broken. For 1.0 and 1.1, a workaround is to use:

import io.thp.pyotherside 1.0
...
importModule('x.y.z', function () {
    call('globals()["x.y.z"].somefunction', [], function(result) {
        ...
    });
};

Please note that the API import (1.0) will still work with newer releases of PyOtherSide, and will carry along the broken behavior, so if you want to write code that works on 1.0 and future versions, you can import the 1.0 API version and use the workaround described above.

In PyOtherSide 1.2.0 (not yet released, see the master branch) a new API import (1.2) will be available with fixed behavior:

import io.thp.pyotherside 1.2
...
importModule('x.y.z', function () {
    call('x.y.z.somefunction', [], function(result) {
        ...
    });
};

As for the more "advanced" imports (from x.y.z import a, b, c and from x.y.z import a as b), can you open a new issue?

@mattaustin
Copy link
Author

Thanks Thomas, I've opened a new issue as requested: #15.

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

No branches or pull requests

3 participants