Comment 3 for bug 1589186

Revision history for this message
John Vandenberg (jayvdb) wrote :

Then a cleaner workaround would be something like

import scipy.optimize
import scipy as sp

assert sp.optimize == scipy.optimize

--

or even just `assert scipy` will do the trick, and will work for multiple scipy.x imports.

The difficulty is that from a symbol/name perspective, which is what pyflakes mostly uses, the name `scipy` is created in the module and never used.

But I am seeing your point .. we know that `import scipy.optimize` adds `optimize` to what will be later named `sp`, and it is used with that alias.

The related problem is that pyflakes doesnt yet do any sanity checking on submodule imports (import x.y). i.e. the following passes

import scipy.foo
import scipy.bar
scipy.baz

It should have errors about `scipy.foo` and `scipy.bar` being unused, and `scipy` on line 3 being an implicit import of `scipy`.

But maybe we can ignore the fact that submodule import usage tracking is not working, and focus on avoiding the error in your scenario of using `import x as y`. i.e. this passes

import scipy.optimize
import scipy
assert scipy

In the above, the 'optimize' part is ignored by pyflakes, so why shouldnt the following also pass:

import scipy.optimize
import scipy as sp
assert sp

I think we have enough information to allow the above the pass, without any regressions.