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

Can't import * from python modules #207

Closed
sqlalchemy-bot opened this issue Jan 23, 2013 · 4 comments
Closed

Can't import * from python modules #207

sqlalchemy-bot opened this issue Jan 23, 2013 · 4 comments
Labels
bug Something isn't working low priority runtime

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Anonymous

<%namespace module="myapp.blah" import="*"/>

seems to do dir(myapp.blah), which picks up everything in that module (variables, imported modules), not just functions. It then dies on "util.partial(callable_, ...)" because callable_ isn't callable.

I've hackily fixed it myself in runtime.py:610, not sure if this is a good fix or not:

- if k[0] != '_':
+ if k[0] != '_' and callable(getattr(self.module, k)):

I also tried getting it to look at module.all rather than dir(), but that didn't import anything at all for some reason.

having a good fix upstream would be appreciated :)

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

Well doing dir() is pretty much what one would expect from importing "", unless there's an __all__ present. I'm not a big fan of the "" thing anyway. But yeah I guess since namespace assumes they are callable, we'd need to do pretty much the check you're doing there.

@sqlalchemy-bot
Copy link
Author

Anonymous wrote:

For anyone reading who can't modify their current install - Another workaround is to prefix everything that isn't a function with an underscore, like

import somelib as _somelib

_a_module_variable = 42

def foo(context):
    return _somelib.foo() + _a_module_variable

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

3bd802b

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority runtime
Projects
None yet
Development

No branches or pull requests

1 participant