[wingide-users] Working with frameworks that dynamically import

Joshua J. Kugler joshua at eeinternet.com
Wed Dec 17 18:42:49 EST 2014

On Wednesday, December 17, 2014 10:02:49 Wingware Support via wingide-users 
> Joshua J. Kugler via wingide-users wrote:
> > I know there are ways to give Wing hints about types (asserts, etc) but I
> > don't want to do that for every object I use in every file I create.
> > 
> > Is there a way to convince Wing to discover these dynamic imports?
> One way to work around this is to run to a breakpoint and then edit.
> When the debugger is active, Wing uses both live runtime state and
> static analysis to fill the auto-completer, source assistant, etc.  This
> is my preferred way to work, for more reasons than just working around
> limitations in static analysis.  You can also immediately try things out
> in the live runtime state using the Debug Probe.

That might work for already-imported items, so I might try that. However, I 
have tried that, basically. I execute run.py, and even in the context of my 
views.py, it still cannot find the types, even though views.py has been 
imported in the Flask init process. Maybe I would need to run views.py as the 
file I execute. The other problem I see: even if I get the types from already 
imported objects, I still can't get a drop down for:

from flask.ext import ...

Because it the object doesn't even exist until the custom importer does its 

> Another idea would be to do something like this before your normal 'from
> flask.ext.login import login_user' import:
> if 0:
>    from flask_login import login_user

I might try that.

> A third more complicated idea is to try to use *.pi files as documented
> at https://wingware.com/doc/edit/helping-wing-analyze-code -- in this
> case, you'ld be copying flask files to different names under a package
> flask and sub-package ext in the pi-files directory of your user
> settings directory (which listed 5th in Wing's About box).  So you would
> have something like:
> pi-files/flask
> pi-files/flask/__init__.pi (empty file)
> pi_files/flask/ext
> pi-files/flask/ext/__init__.pi (empty file)
> pi-files/flask/ext/flask_login.pi (which is flask_login.py renamed)

Sounds like an interesting idea. Might have to try that.

Another idea I thought of was this: The custom importer that is triggered by 
"from flask.ext import" is this:

ExtensionImporter(['flask_%s', 'flaskext.%s'], __name__)

According to the docs, it does this:

When a user does ``from flask.ext.foo import bar`` it will attempt to import 
``from flask_foo import bar``

Is there a way to tell Wing to
1) Have wing rifle though all modules it finds of pattern flask_* and look for 
importable objects; and
2) recognize the 'from flask.ext.foo import bar' pattern and turn it into 
'from flask_foo import bar' for the Source Assistant's benefit?


Joshua Kugler
Part-Time System Admin/Programmer
http://www.eeinternet.com - Fairbanks, AK
PGP Key: http://pgp.mit.edu/  ID 0x73B13B6A

More information about the wingide-users mailing list