Comment 1 for bug 1589186

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

So the flake8 error F401 is pyflakes reporting the following for line 1: 'scipy.optimize' imported but unused.

Which is correct for the sample code you have given.

scipy.optimize is unused, as the object with name 'scipy' is not accessed on line 2; instead the import on line 2 creates a new object 'sp' which just happens to be a module called 'scipy' in the import lookup system.

So I dont believe this is a bug, based on the sample code provided.

I am guessing that you dont really want to print scipy.optimize ? You are trying to hide the error, by doing a dummy usage?

The following will do the import, and hide the pyflakes error

import scipy.optimize as _
import scipy as sp

del _

def x():
    return sp.foo()

If you really need to print or access scipy.optimize, the this works

import scipy.optimize
import scipy as sp

print(scipy.optimize)

def x():
    return sp.foo()

But maybe your real code cant be solved those ways, in which case let me know the project and I'll take a look at the problem with real code.