Issue #207 resolved

Can't import * from python modules

created an issue

<%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, 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 :)

Comments (3)

  1. Mike Bayer repo owner

    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.

  2. guest reporter

    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 + _a_module_variable
  3. Log in to comment